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

[REBOL] Re: En Masse block operations

From: ryanc:iesco-dms at: 16-Oct-2001 10:27

Dont use 'foreach. 'Foreach makes a copy of the value, bungling your method. Use 'forall or 'repeat. I like using 'repeat for this sort of thing because I can do it without the awkward [block: head block] at the end. Also you might want to use 'block? instead of 'series? to validate whether an operation is warranted. Many other data values are considered a series...
>> series? "abc"
== true
>> series? ftp://bob.jones.com
== true
>> series? [ned--none--com]
== true
>>
--Ryan 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"] > blk: do-all blk head ; set all members to head > ; result sought: > >>[[1 2 3 4] [5 6 7 8] [9 10 11 12] [13 14 15 16 17] "one"] > ; I've started by this simple function, which is not doing just > ; what I want: > REBOL[] > do-all: func[blk[block!] ][ ;cmd[word!] > foreach member blk[ > if series? member[ > member: next member > print mold member > ] > ] > blk > ] > test: [[1 2 3 4] [5 6 7 8] [9 10 11 12] [13 14 15 16 17] "one"] > print mold do-all test > ;and I get > >> do %sample.r > Script: "Untitled" (none) > [2 3 4] > [6 7 8] > [10 11 12] > [14 15 16 17] > "ne" > [[1 2 3 4] [5 6 7 8] [9 10 11 12] [13 14 15 16 17] "one"] > > TIA > -- > Tim Johnson <[tim--johnsons-web--com]> > http://www.johnsons-web.com > -- > To unsubscribe from this list, please send an email to > [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Ryan Cole Programmer Analyst www.iesco-dms.com 707-468-5400