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

[REBOL] Re: En Masse block operations

From: joel:neely:fedex at: 16-Oct-2001 12:05

Hi, Tim, Tim Johnson wrote:
> Hello All: > I would like to apply the same operation to all members > of a nested block. > ;Example: > blk: [[1 2 3 4] [5 6 7 8] [9 10 11 12] [13 14 15 16 17] "one"] > blk: do-all blk next ; set all members to next element > ;result sought: > >>[[2 3 4] [6 7 8] [10 11 12] [14 15 16 17] "ne"]
Sounds like a job for MAP to me...
>> blk: [[1 2 3 4] [5 6 7 8] [9 10 11 12] [13 14 15 16 17] "one"]
== [[1 2 3 4] [5 6 7 8] [9 10 11 12] [13 14 15 16 17] "one"] ... then ... map: function [[catch] b [block!] f [function!] /all] [r v] [ r: make block! length? b foreach c b [ if any [found? v: do [f c] all] [append/only r v] ] r ] ... and, finally ...
>> map blk func [s][next s]
== [[2 3 4] [6 7 8] [10 11 12] [14 15 16 17] "ne"] ... or ...
>> x: map blk func [s] [next s]
== [[2 3 4] [6 7 8] [10 11 12] [14 15 16 17] "ne"]
>> x: map x func [s] [next s]
== [[3 4] [7 8] [11 12] [15 16 17] "e"]
>> map x func [s] [head s]
== [[1 2 3 4] [5 6 7 8] [9 10 11 12] [13 14 15 16 17] "one"] HTH! -jn- -- This sentence contradicts itself -- no actually it doesn't. -- Doug Hofstadter joel<dot>neely<at>fedex<dot>com