[REBOL] Make-Object
From: al::bri::xtra::co::nz at: 19-Oct-2001 21:03
Make-Object grabs all the set-word! in a object spec or in the contained
blocks and puts these in the object spec. Words outside the object can be
acessed by using 'get and 'set.
make object! [
SetWords?: function [Spec [block!]][Words][
Words: make block! 10
foreach Value Spec [
any [
if all [
set-word? :Value
not found? find Words :Value
][
append Words :Value
]
if block? :Value [
append Words SetWords? Value
Words: unique Words
]
]
]
Words
]
set 'Make-Object function [
"Scans a Spec looking for set-word inside them."
Spec [block!]
][
SetWords
][
SetWords: SetWords? Spec
if not empty? SetWords [
append SetWords none
probe insert Spec SetWords
]
make object! Spec
]
]
Use it like:
o: make-object [
t1: 1
fun: does [
t2: 2
t3: 3
t1: t2 + t3
set 'HelloWord "Hello outside World!" ; Set outside 'o.
]
]
Andrew Martin
ICQ: 26227169 http://valley.150m.com/