noob question: foreach usage
[1/3] from: dougedmunds::gmail at: 15-Apr-2008 17:47
How do I print the values of x1 and x2 in the foreach loop?
;---- start code
send2: func [
arglist
][
print arglist ; prints the values
foreach arg arglist [print arg ] ; prints 'x1' 'x2', not values
]
view layout [
field1: field "3"
field2: field "4"
button "send" [
x1: field1/text
x2: field2/text
send2 [x1 x2]
]
]
;-----end code
[2/3] from: gregg:pointillistic at: 15-Apr-2008 18:50
Hi Doug,
D> How do I print the values of x1 and x2 in the foreach loop?
D> ;---- start code
D> send2: func [
D> arglist
D> ][
D> print arglist ; prints the values
D> foreach arg arglist [print arg ] ; prints 'x1' 'x2', not values
D> ]
[print get arg]
-- Gregg
[3/3] from: anton::wilddsl::net::au at: 16-Apr-2008 11:42
Hi Doug,
'x1' and 'x2' *are* values - values of type word!.
What you want are the associated values of
the words, so you need to reduce the words.
(Maybe you also want the words themselves ?
but usually we don't.)
You can reduce before passing to the function,
or afterwards, inside the function, eg:
send2: func [arglist][
?? arglist
probe reduce arglist
foreach arg reduce arglist [?? arg]
foreach arglist reduce arglist [probe arglist]
]
x1: "hello"
x2: "world"
send2 [x1 x2]
However, maybe what you want is just:
send2: func [arglist][
foreach val arglist [?? val]
]
x1: "hello"
x2: "world"
send2 reduce [x1 x2]
Anton.
DougEdmunds wrote: