On Tue, May 12, 2009 at 8:04 PM, Boyko Bantchev <[email protected]> wrote: > Taking into account the direction of evaluation and the absence of > initial value from which to start it, J's / is closest to one of the four > Haskell folds, namely foldr1. (For several reasons the analogy is > not full, though.)
This gets into issues of features for the sake of features vs. simplicity. I believe APL's reduce predates fold (and was probably the inspiration for fold). But since operations on arrays are so foreign to other languages, people sort of jammed a lot of "related-seeming" features into fold because the languages which would be implementing fold could not provide them. J, on the other hand, can reverse the direction of processing (in two senses of the word, yielding four possibilities involving reversal or not). ;/2 3 5 +-----+ ¦2¦3¦5¦ +-----+ ;~/2 3 5 +-------+ ¦+---+¦2¦ ¦¦5¦3¦¦ ¦ ¦+---+¦ ¦ +-------+ ;/@|.2 3 5 +-----+ ¦5¦3¦2¦ +-----+ ;~/@|.2 3 5 +-------+ ¦+---+¦5¦ ¦¦2¦3¦¦ ¦ ¦+---+¦ ¦ +-------+ Also, for any well behaved function, the initial value can be supplied in the list itself. Anyways, according to the wiki page, fold is a family of higher-order functions, so technically speaking no language ever implements fold -- instead, each language implements members of the fold family. -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
