[REBOL] Re: 'Foreach questions
From: brett:codeconscious at: 22-Dec-2002 8:47
Hi Tim,
After this line:
col-names: set [a b c d] ["one" "two" "three" "four"]
A will be "one", B will be "two", etc.,.
col-names will be the block of strings ["one" "two" "three" "four"] not [a b
c d].
Inside your foreach loop you are using
set 'col-names row
So you are setting the *word* col-names itself to each of the data blocks in
turn - again nothing to do with A, B, C, D. That is why a, b, c, d do not
change each row as you print them.
This is probably closer to what you want:
columns: [a b c d]
col-names: ["one" "two" "three" "four"]
data: [[1 2 3 4] [5 6 7 8] [9 10 11 12]]
foreach row data [
set columns row
prin mold col-names prin mold a
prin mold b prin mold c print mold d
]
or even:
columns: [a b c d]
col-names: ["one" "two" "three" "four"]
data: [[1 2 3 4] [5 6 7 8] [9 10 11 12]]
foreach row data [
set columns row
print [mold col-names mold reduce columns]
]
Regards,
Brett.