| Map et al arguments are backwards |
| 4 points by tokipin 6102 days ago | 25 comments |
|
| The order of the arguments to map are backwards. Currently it is: (map fn list)
It should be: (map list fn)
The reason isn't SVO or CNN or anything like that, but simply that most of the time (or so I think), the size (in characters and line numbers) of the fn is larger than the size of the list, so what you get is: (map (blee (blah
(+ @(bleh meh)
(bluu meh))
(* $(if moo))))
list)
As you can see, the poor list is buried. When you start reading the expression, starting from '(map', you can't grasp what the whole expression is doing because your eyes are blasted with a monstrous fn. But if the arguments are in the proper order: (map list
(blee (blah
(+ @(bleh meh)
(bluu meh))
(* $(if moo)))))
You can readily see or at least anticipate what the expression is doing. Having the smaller half of the expression at the front makes the whole expression more readable, and if you know what the list is, you can anticipate the type of stuff fn will do and you will have some anchorage with which to parse it better, where you would otherwise have to shoot your eyes to the bottom and shoot them back to the top.An idiomatic form could then be: (map list (fn (x y z)
(dostuff x y)
(domorestuff z)))
I know the lambda wouldn't be multivariate in this case, but though I use map here I'm talking generally.The function could also be made to accept different orders, which would allow it to be curried at any argument(s) with the succinct "implied underscore" form of [... _ ...]. |