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

[REBOL] 'dynamic append' Re:

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