Why does for-each
and set-for-each
have a different parameter order?
Well, for-each
is from Scheme. The call is (for-each f a-list)
. This order is the same as map
, which makes it easy to remember. The advantage of having the list last, is that the list argument usually leads to a larger expression (and it makes it easier to spot f
, when it is first.
It would be natural to use the same order in set-for-each
, but I bet the reason is that all the other set-functions all have the set as the first argument.
Interesting, the short-arguments-come-first principle is the very reason I prefer for the list to come first. The function argument is virtually always a lambda for me.
IMO, the scheme order isn’t natural at all. I’ve had actual bugs caused by the argument order of sequence-map
: https://github.com/jackfirth/rebellion/issues/299
(….but in a language with currying, this all goes out the window)