Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Maplist?

From: carl:cybercraft at: 9-Sep-2001 13:07

On 09-Sep-01, David Ness wrote:
> I've look thru the documentation, but haven't had the answer to a > very simple question jump out at me yet. > Question: > What converts ["123" "45667"] to [123 45667] > or generalizing: > How do I generate the block that is the result of applying some > function to each element of an existing block (the classical > Lisp `Maplist') function; > perhaps more importantly, > what documentation should I look at that would point me in the > direction to solutions to this class of problems...
I see others have replied with more functional functions while I was working out the following rather limited one, but here it is anyway... convert: func [series [series!] apply [function! native! action!]][ head forall series [change series apply first series] ]
>> convert [1 2 3 "4" "5" "6"] :to-integer
== [1 2 3 4 5 6]
>> convert [1 2 3 "4" "5" "6"] :to-string
== ["1" "2" "3" "4" "5" "6"]
>> convert [1 2 3 a b c] :to-string
== ["1" "2" "3" "a" "b" "c"]
>> convert [1 2 3 a b c] :to-file
== [%1 %2 %3 %a %b %c]
>> convert ["123" "abc" "xyz"] :first
== [#"1" #"a" #"x"]
>> convert ["123" "abc" "xyz"] :reverse
== ["" "" ""]
>> convert convert ["123" "abc" "xyz"] :reverse :head
== ["321" "cba" "zyx"] The limitations are that you can't use a function's refinements (as with Larry's map function) or functions that require more than one argument, so the likes of append will return an error. -- Carl Read