[REBOL] Words, Bindings and Contexts. (10)
From: lmecir:geocities at: 29-Jul-2000 20:27
My apologies to everybody. The Make-object! and R-make-object!
functions shall be repaired (missing colon before Elem in append
words to word! :elem) The correct versions:
make-object!: func [
{make object! simulation}
spec [block!]
/local words result
] [
words: make block! 0
foreach elem spec [
if set-word? get/any 'elem [
append words to word! :elem
]
]
result: make-context words
result/self: result
do bind spec in result 'self
return get/any in result 'self
]
r-make-object!: func [
{make object! simulation}
spec [block!]
/local words result
] [
words: make block! 0
foreach elem spec [
if set-word? get/any 'elem [
append words to word! :elem
]
]
result: make-context words
result/self: result
do bind/copy spec in result 'self
result
]
{
here is a code that can behave "unexpectedly":
}
f: func [level] [
make object! [
a: 2 * level
b: either zero? level [
f 1
] [
none
]
a: a + 1
]
]
probe f 0
{
The results:
>> probe f 0
make object! [
a: 0
b: unset
]
}
f: func [level] [
r-make-object! [
a: 2 * level
b: either zero? level [
f 1
] [
none
]
a: a + 1
]
]
probe f 0
{
The results:
>> probe f 0
make object! [
a: 1
b:
make object! [
a: 3
b: none
]
]
}