[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Standard Libraries: (was: and Lua marches on)
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 17 Dec 2009 13:32:19 +0200
On Thu, Dec 17, 2009 at 12:59 PM, steve donovan
> Well, they are classically defined for ordered lists.
And then consider the useful map2(fun,t1,t2) where fun takes two
arguments, the corresponding values from t1 and t2. A naive
implementation could return the result of applying the function to the
intersection of two hash-like tables. Or fun could be expected to
handle the case where one of its two arguments were nil. We would be
in novel territory, although I would enjoy being wrong here.
Also, classical map() is over values. Why not the keys as well? For
instance, we could pass the key as a second argument to the function,
and return the new value as well as optionally the new key.
Pontentially useful, probably not a good idea to overload a simple
word like 'map' in this way. Better to call it something like
'transform' and use usual ordering, as in transform(function(key,val)
return key,val end, t) which is an identity map.
BTW, map(fun,pairs(t)) feels even better, although there's another
problem for map2 there...