[REBOL] Re: Maplist?
From: larry:ecotope at: 8-Sep-2001 15:23
Hi David,
Here is a short and simple version of MAP. I agree it would be nice if RT
would implement a fast internal version of MAP. I find it extremely useful.
map: func [f1 b /local out][
out: copy []
repeat el b [append/only out f1 :el]
out
]
Use it like this for a named function (note the : prefix is needed to delay
full evaluation).
>> map :to-integer ["123" "45667"]
== [123 45667]
If the named function needs a refinement switch you delay evaluation with a
leading ' , like this:
>> map 'sine/radians [0 30 90]
== [0 -0.988031624092862 0.893996663600556]
You can also use it with an anonymous function (defined on the fly) like
this:
>> map func [x][x * x] [1 2 3]
== [1 4 9]
I am very interested in the list operators of Scheme, Lisp, and modern
functional languages like Haskell, Miranda, and Clean. I have implemented
many of them in REBOL. So feel free to ask more on this topic.
You might also benefit from Ladislav Mecir's highfun.r library:
http://www.sweb.cz/LMecir/highfun.r
Cheers
-Larry