[REBOL] Re: reduction
From: greggirwin:starband at: 6-Oct-2001 11:38
Hi Carl,
<< map ? Is that a REBOL/Command word? View says it knows nothing about
it. >>
Larry Palmiter, and I think Ladislav Mecir, have written map functions which
may be what Hwee Kwang was referring to. Here is Larry's:
; 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]
--Gregg