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

variable variable

 [1/9] from: ammoncooke::yahoo::com at: 31-May-2001 15:11


Hi, Patients with my pesky questions, please, the project is about complete. I need to name a variable by a variable name: item: tool I want to name a variable tool-count because that is what the value of item is. Please Help! Ammon

 [2/9] from: lmecir:mbox:vol:cz at: 1-Jun-2001 0:16


you may want something like:
>> var-name: ask "Variable, please: "
Variable, please: tool-count == "tool-count"
>> value: ask "Value, please: "
Value, please: "tool-chest" == {"tool-chest"}
>> set to word! var-name do value
== "tool-chest"
>> tool-count
== "tool-chest"

 [3/9] from: pa:russo:perd at: 1-Jun-2001 8:32


> I need to name a variable by a variable name: > >item: tool > >I want to name a variable tool-count because that is what the value >of item is. > >Please Help! >Ammon >
I'm not sure to have understood what you need, but this could do the trick:
>> do reduce [to-set-word ask "Variable name, please: " 23]
Variable name, please: pippo == 23
>> pippo
== 23 -- Paolo Russo [pa--russo--perd--com] _________________ PERD s.r.l. Virtual Technologies for Real Solutions http://www.perd.com

 [4/9] from: carl:rebol at: 1-Jun-2001 2:36


Judging from the replies, we're not sure what your question is. Use: item: 'tool The variable ITEM now refers to the variable TOOL. To get its value: print get item Example: tool: "hammer" item: 'tool print get item == hammer tool: "chisel" print get item == chisel Does that answer your question?

 [5/9] from: ammoncooke:yah:oo at: 7-Jun-2001 14:30


Hold on while I, with my weak english skills, try to words this so the gurus know what I am talking about.... Ok, here we go... What I need is this: I am getting a value from a text-list: lst1-rnd: lst1/text: random/only lst1/data now create a variable: do reduce[to-set-word lst1-rnd: 1] now how do I access the value of the value of lst1-rnd without explicitly calling it?? Thanks!! Ammon PS the random function always picks the items from the list in the SAME order. The reason I tried the random function is to avoid that. What am i doing wrong??

 [6/9] from: ammoncooke:yah:oo at: 7-Jun-2001 14:23


If I understand properly, then tool: hammer do reduce[to-set-word tool: 1] Would create a variable with the name of hammer, & its value would be 1??? It appears to work, now I need to get at the value of hammer without knowing that there is a variable by the name of hammer. Does that make any sense?? In fine, I need to access the value of the value of tool. ;)) Thanks!! Ammon

 [7/9] from: joel:neely:fedex at: 13-Jun-2001 0:34


Ammon Cooke wrote:
> Hold on while I, with my weak english skills, try to words > this so the gurus
<<quoted lines omitted: 7>>
> now how do I access the value of the value of lst1-rnd > without explicitly calling it??
I'm still unclear what you mean by the phrase "without explicitly calling it". Let's make a simple example
>> pig
** Script Error: pig has no value ** Near: pig
>> cow
** Script Error: cow has no value ** Near: cow
>> duck
** Script Error: duck has no value ** Near: duck ; just to prove there's nothing up my sleeve... ;-) Now,
>> some-word: random/only [pig cow duck]
== duck
>> do reduce [to-set-word some-word "quack"]
== "quack" At this point, we've set the word DUCK (which formerly was not set to anything) to the string "quack". We can prove this by
>> duck
== "quack" To get at this word (and its current value) we must somehow remember what we called it. Its "name" is still in SOME-WORD, so we can do one of the following:
>> reduce reduce [some-word]
== ["quack"]
>> print reduce [some-word]
quack Once we change the value of SOME-WORD, we can't use it to get back to DUCK and hence to "quack". So, if you're going to change SOME-WORD, be sure to save its value somewhere, such as in a block. For example: repeat i 5 [ some-word: random/only [pig cow duck chicken horse dog cat] do reduce [to-set-word some-word i] if none? find barnyard some-word [append barnyard some-word] ] == [duck chicken cat dog] foreach indirect-word barnyard [ print [indirect-word do reduce [indirect-word]] ] duck 1 chicken 3 cat 4 dog 5 If you want to keep something, you have to remember where you put it, one way or another!
> PS the random function always picks the items from the list > in the SAME order. The reason I tried the random function > is to avoid that. What am i doing wrong?? >
Try using the /SEED refinement to RANDOM. -jn- ------------------------------------------------------------ Programming languages: compact, powerful, simple ... Pick any two! joel'dot'neely'at'fedex'dot'com

 [8/9] from: ammoncooke:yah:oo at: 13-Jun-2001 10:33


Thanks!! That is exactly the information I was looking for. Glad your telepathy works so well, ;)) Ammon

 [9/9] from: g:santilli:tiscalinet:it at: 13-Jun-2001 19:05


Hello Joel! (Just being picky...) On 13-Giu-01, you wrote: JN>>> do reduce [to-set-word some-word "quack"] JN> == "quack" set some-word "quack" JN>>> reduce reduce [some-word] JN> == ["quack"] get some-word :-) Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted