Hi Bryce,
I'm not sure I understand your question. The way I interpret what you are
saying, the following mechanisms may prove useful.
Evaluating the following for loop
(Note here I am using to set-word!)
for i 1 10 1 [ print mold to set-word! join 'var [i] ]
results in
var1:
var2:
var3:
var4:
var5:
var6:
var7:
var8:
var9:
var10:
To assign a value use set
(Note here I am using to word!, not to set-word! You could also use
set-word! but its not necessary)
for i 1 10 1 [
set to word! join 'var [i] i
print [
to word! join 'var [i]
get to word! join 'var [i]
]
]
Evaluating this for loop generates the following output:
var1 1
var2 2
var3 3
var4 4
var5 5
var6 6
var7 7
var8 8
var9 9
var10 10
The varN words we created are available outside of the for loop:
var1
== 1
var2
== 2
var3
== 3
Or to automate the process:
for i 1 10 1 [ print [mold to word! join 'var [i] " " get to word! join
'var [i] ] ]
var1 1
var2 2
var3 3
var4 4
var5 5
var6 6
var7 7
var8 8
var9 9
var10 10
We can unset the varNs as well:
for i 1 10 1 [ unset to word! join 'var [i] ]
Now, var1 no longer exists
var1
** Script Error: var1 has no value.
** Where: var1
Another mechanism that may come in handy:
Here I set the word test to the set-word! value var1.
i: 1 test: to set-word! join 'var [i]
== var1:
:test
== var1:
When I attempt to get the value of var1, I generate an error because var1
was not assigned a value:
get :test
** Script Error: var1 has no value.
** Where: get :test
Now I set the value of var1 to 10. It works like this. REBOL dereferences
the word test and retrieves its value, which is the set-word! var1:. A
set-word! is like a magnet, it attaches itself to whatever value it finds
next. That value is 10:
test 10
== 10
The word test continues to evaluate to var1, as it did before:
:test
== var1:
We can now safely retrieve the value of var1:
get :test
== 10
Or to illustrate it differently:
unset 'var1
var1
** Script Error: var1 has no value.
** Where: var1
i: 1 test: to set-word! join 'var [i]
== var1:
test 10
== 10
var1
== 10
A final remark. I would normally just collect my stuff in a block, instead
of using set-words:
for i 1 10 1 [
append [] i
]
== [1 2 3 4 5 6 7 8 9 10]
or if you want to later retrieve the block:
result-block: for i 1 10 1 [
append [] i
]
== [1 2 3 4 5 6 7 8 9 10]
result-block
== [1 2 3 4 5 6 7 8 9 10]
At 12:43 PM 5/31/00 -0700, you wrote:
First let me tell you I took a C++ course(1301) years ago and haven't done
too much programing since. I'm just installed a small LAN and am trying
to learn rebol for maitnance and fun
Now my problem...I need to make the value of var1:test1 into the name of a
new variable that can hold a value like test1:4. Then the programs loops
and var1:test2 and I want test2:some#. I can make the value of var1
increment I just can't figure out how to make test#:some# from var1:test#.
Thanks for any help, I looked all over the sites documentation but didn't
see what I needed...if its on there just point me in the direction to look
if its easier. Thanks, Bryce
--
Why is College Club the largest and fastest growing college student site?
Find out for yourself at http://www.collegeclub.com
;- Elan [: - )]