'dynamic append' Re:
[1/4] from: bhandley:zip:au at: 24-Jul-2000 10:21
Hi Hendrik-Jan,
You're almost there - here is a simple solution.
> append/only test rejoin ["block1_"A ": copy []"]
> do last test
test: []
a: 12
append/only test rejoin ["block1_"A ": copy []"]
last-block: do last test
append last-block "whatever you want"
so now try:
>> block1_12
== ["whatever you want"]
Brett Handley
[2/4] from: bosch::geo::uu::nl at: 24-Jul-2000 2:32
hi Brett,
it works great!
thanks very very much!
HJ
[3/4] from: rebol:keithdevens at: 23-Jul-2000 20:01
What you're trying to do is use dynamic variable names. Some languages like
Perl allow this. Perl calls them symbolic links and lets you do things like
--------------
$var = "variable_name";
${$var} = "hello!";
print $variable_name;
--------------
outputs: "hello!"
The reason your "append (join "block1_"A) "some data" """"" thing doesn't
work is because you're appending to the string value "block1_1" or whatever
the value of A is.
>> test: []
== []
>> a: 1
== 1
>> append/only test rejoin ["block1_"A ": copy []"]
== ["block1_1: copy []"]
>> do last test
== []
>> append (join "block1_"A) "--appended_string"
== "block1_1--appended_string"
But if you make a word whose value is the word that you want to get (this
acts as the "symbolic link") you can get at the value of the original word.
>> tempword: to-word join "block1_" a
== block1_1
>> get tempword
== []
(get tempword) now points to the same place as 'block1_1'
>> append (get tempword) "value"
== ["value"]
>> block1_1
== ["value"]
>> get tempword
== ["value"]
As you can see they're the same :) If there's anything I missed or if
there's another way to do it, please let us know!
Keith
[4/4] from: rebol:keithdevens at: 24-Jul-2000 17:28
Wow, I sent this message yesterday at around 8:00PM. Why did it take almost
24 hours to make it to the list?