[REBOL] Re: Is there a REBOL construct similar to the "map" word as used in Logo
From: greggirwin:mindspring at: 28-Jun-2002 11:39
Hi Gerard,
<< Now is another question relative to the word "map" I already used in Logo
for working on agregates - that is data collections - and doesn't seem to
exist per se in the same form under REBOL. >>
There area few versions floating around out there. Here's one by Larry:
; Larry Palmiter
map: func [fn blk args /local result][
result: copy []
repeat el blk [append/only result fn :el args]
return result
]
; 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]
HTH!
--Gregg