[REBOL] Re: Setting argument values in objects
From: nitsch-lists:netcologne at: 6-Nov-2001 4:02
RE: [REBOL] Setting argument values in objects
[moeller_thorsten--GMX--De] wrote:
> Hi list,
>
> i have the following problem with objects.
>
> I have an object called "proctype-obj" having about ten arguments for
> different processortypes.
>
> I have variable ( word ) containing a string which is the path to the
> objects argument like
>
> proc: "proctype-obj/IntelPentium(R)processor"
>
> I have another variable containig an integer value like
>
> count: 2
>
> How can i set the argument in the object
> (proctype-obj/IntelPentium(R)processor) to the value of the count variable???
>
hmm, do you really need "IntelPentium(R)processor"?
because putting "()" in rebol-pathes will not work..
building and using paths is a bit complicated.
could you use a hash! instead, like
proctype: make hash!["IntelPentium(R)processor" 2 "mychip" 3]
something like (untested)
associate: func["change or append" block key value /local here][
either here: find/skip block key 2
[here/2: value] [repend block [key value]]
]
.. associate proctype "mychip" 24
to add entries and
select/skip block "mychip" 2
to get it back.
without [/skip .. 2]
instead of finding a key 'find could find also a value,
so i use /skip's for the general case.
if you are sure no value is like a key, you can drop them.
some ways are if you use string-keys, never store
values in strings, or make them somehow different.
- Volker