hi,

the one i use has a deep refinement:


===============CODE===============

REBOL [
Title: "Map Function"
Date: "24-November-1999"
Author: "Larry Palmiter"
Purpose: { Maps a function of one arg
onto a (nested) block of values.
}
]

map: func [
"Maps a function onto elements of a block"
:f "function (use parens for literal)"
b [block!] "block of values"
/deep "maps function into nested blocks"
/local out
][
out: make block! length? b
if paren? :f [f: f]
foreach el b [
either block? el [
either deep [
append/only out map/deep f el
][
append/only out el
]
][
append out f el
]
]
]

===========END OF CODE=============


works beautifully. many thanks to Larry Palmiter for a great function!

regards
hk


Gregg Irwin wrote:

> 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
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to