[REBOL] Re: Setting argument values in objects
From: geza67:freestart:hu at: 5-Nov-2001 23:13
Hello Thorsten,
> proc: "proctype-obj/IntelPentium(R)processor"
First, get rid of the parens! REBOL will parse them as a paren! value.
> (proctype-obj/IntelPentium(R)processor) to the value of the count variable???
If you have only one-level deep objects (i.e. not a/b/c),
set in proctype-obj 'IntelPentiumRprocessor
Below you find two functions, allowing to use the normal path
notation, even in case of nested objects. SETP works with object-path
lists only, while in the first list argument of SETX you can put even
(still) nonexistent words (and objects, naturally, even mixed) to set.
--------------------------
rebol []
setp: function [{Set multiple values at a time on block of objects (in path notation)}
where-list [any-block!] value-list [any-block!]][lhead ltail i][
i: 0
foreach elem where-list [
i: i + 1
if (type? :elem) = path![
ltail: last lhead: to-block :elem
lhead: head remove back tail lhead
do compose [set/any in (to-path lhead) (to-lit-word ltail)(pick value-list i)]
]
]
]
setx: function [{Set multiple values at a time on block of
objects (in standard path notation) or words}
where-list [any-block!] value-list [any-block!]][lhead ltail i][
i: 0
foreach elem where-list [
i: i + 1
do compose [set/any
(switch type?/word :elem [
path! [
ltail: last lhead: to-block :elem
lhead: head remove back tail lhead
compose [in (to-path lhead)]
]
word! [
ltail: :elem
[]
]
])
(to-lit-word ltail)(pick value-list i)]
]
]
a: context [ b: context [c: none]]
d: context [ e: none]
x: 'a/b/c
setx [a/b/c d/e y z] [1 2 3 4]
setp [a/b/c d/e] [1 2]
? a
? d
probe y
probe z
--------------------------
Hope, this helps!
--
Best regards,
Geza mailto:[geza67--freestart--hu]