How to transform a string into a word and get its associated value
[1/9] from: gerardcote:sympatico:ca at: 21-Jun-2005 17:07
Hi list,
Since I got no cue about my recent parse submit, I will restructure my problem another
simpler way:
I have some word called 'name and its associated integer value 250.
>> name: 250
== 250
I can verify the value associated with the word 'name from the global system/words object.
>> print system/words/name
250
Now for the difficult part (at least to me). I get another word called 'info that contains
a reference to my former word 'name.
>> info: "name"
== "name"
When I ask to display its value, the word name is correctly associated but it remains
a string and is in no way considered as a real
word called 'name.
>> print system/words/info
name
What I would get is a substitution of the string "name" for the real word 'name and then
the associated value could be accessed -
indirectly.
I feel there is some way to do it but I can't up to now say which it is ????
I tried some basic knowledge I have but the result is not the one I want.
>> print system/words/:info
** Script Error: Invalid path value: name
** Where: halt-view
** Near: print system/words/:info
May be I could join or append the 2 parts (system/words and info) in some way but I have
yet to get it done.
Thanks,
Gerard
[2/9] from: volker:nitsch:gmai:l at: 22-Jun-2005 0:23
On 6/21/05, Gerard Cote <[gerardcote--sympatico--ca]> wrote:
> Hi list,
> Since I got no cue about my recent parse submit, I will restructure my problem another
simpler way:
<<quoted lines omitted: 7>>
> >> info: "name"
> == "name"
!>> info: 'name
== name
!>> get info
== 250
> When I ask to display its value, the word name is correctly associated but it remains
a string and is in no way considered as a real
> word called 'name.
<<quoted lines omitted: 14>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
-Volker
Any problem in computer science can be solved with another layer of
indirection. But that usually will create another problem.
David
Wheeler
[3/9] from: Izkata:Comcast at: 21-Jun-2005 17:46
>> A: 250
== 250
>> B: "A"
== "A"
>> get in system/words to-word B ;one-line way to do it
== 250
>> C: to-word B ;two-line way to do it
== A
>> system/words/:C
== 250
You're using a string, that's to problem.. But I thank you for
asking in that way, I needed this very thing for something of my
own and couldn't figure it out before now!
-Izzy Boy
[4/9] from: tom::conlin::gmail::com at: 21-Jun-2005 16:22
Hi Gerard,
>> foo: 5
== 5
>> bar: "foo"
== "foo"
>> get to-get-word bar
==5
is that what you are looking for?
On 6/21/05, Gerard Cote <[gerardcote--sympatico--ca]> wrote:
> Hi list,
> Since I got no cue about my recent parse submit, I will restructure my problem another
simpler way:
<<quoted lines omitted: 25>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
... nice weather eh
[5/9] from: gerardcote:sympatico:ca at: 21-Jun-2005 19:51
Thanks Izkata,
This is just what I need.
I must admit that until you submitted your own solution I had not been able to figure
the exact syntax by my self...
But I was not very far of yours!
In fact my use of get in waas incorrect - I was missing the required type conversion
to-word !!!
Regards,
Gerard
[6/9] from: th72::dds::nl at: 22-Jun-2005 11:18
I think it's very easy, if i understand you right.
Use this for example:
>> test: 99
== 99
>> name: "test"
== "test"
>> name
== "test"
>> make word! name
== test
>> do make word! name
== 99
Tim
make word! "test"
Gerard Cote wrote:
[7/9] from: th72::dds::nl at: 22-Jun-2005 11:19
I think it's very easy, if i understand you right.
Use this for example:
>> test: 99
== 99
>> name: "test"
== "test"
>> name
== "test"
>> make word! name
== test
>> do make word! name
== 99
Tim
make word! "test"
Gerard Cote wrote:
[8/9] from: gabriele::colellachiara::com at: 22-Jun-2005 15:23
Hi Gerard,
On Tuesday, June 21, 2005, 11:07:22 PM, you wrote:
GC> Since I got no cue about my recent parse submit, I will
GC> restructure my problem another simpler way:
>> name: 250
== 250
>> string: "name"
== "name"
>> get to word! string
== 250
No need for IN, converting to word already binds to the global
context.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[9/9] from: gerardcote:sympatico:ca at: 22-Jun-2005 22:41
Hi list,
and the winner is (my preferred one that is) :
> >> name: 250
> == 250
<<quoted lines omitted: 4>>
> No need for IN, converting to word already binds to the global
> context.
Interesting and useful info for me since I recently looked at 'bind and the question
remaining unanswered to me was how to bind a
variable defined in a local context to some word defined in the global context.
Thanks you Gabriele and every others that also have submitted helpful solutions. I'll
look at them later in an effort to compare
their respective value and learn more about REBOL.
Regards,
Gerard
P.S. If you asked yourself what was the usefulness of all this let me simply say that
I am working on a REBOL version of a printf
work alike. Many languages offer this instruction: C, awk, ...
The proposed syntax will be something like :
printf ["%-d| %|6.2f| %08b %-6s" n 123 123 "allo"] "%"
the last part is a delimiter and will be suppressed during the final stage.
If you look in detail at the different parts her is a summary for all of them:
a beginning field delimiter %
an optional | char (used for vertical alignment during printout if desired)
an optional alignment flag can be - + " " 0 c (left aligned for minus, add sign for
plus,
left padding with blanks or zeros, field
centering for c)
an optional field width (number)
an optional precision (dot followed by number)
a conversion code (specifies conversion type from the original data to its
final form,
present supported forms are b-binary, o-octal, h-hex, d/f-decimal,
e/g-scientific form and s-string)
a final optional | char (used for vertical alignment during printout if desired)
Some details have yet to be done before the printf is completed. I'll announce it for
posting to the library for study when ready to
release if there is some interest. Also welcomed is any suggestion to enhance the usability
of the actual printf, which I really
never found user friendly at all.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted