[REBOL] Re: Private Object Function
From: rebol:techscribe at: 17-Jan-2001 22:43
I was really in a hurry when I wrote this stuff. The class function I
included was untested and incorrect. The corrected version is:
class: func [ default! [object!] spec [block!] ] [
set [_ private-block _ published-block _ public-block] spec
return make default! [
if private-block [private: make object! private-block]
if published-block [published: make object! published-block]
if public-block [public: make object! public-block]
]
]
A better version is:
class: func [[catch] default! [object!] spec [block!] /local
class-spec] [
class-spec: make block! 6
foreach [section definition] spec [
either block? definition [
insert class-spec compose/deep [
(to set-word! section) make object! [(definition)]
]
][
throw make error! join {Expected definition of type block!.
Received } [mold definition " of type " mold type? definition "
instead."]
]
]
return make default! class-spec
]
The second version is more flexible in that it permits spec blocks that
exclude any or all of the exposure signifiers (public, published, or
private), the declarations may occur in any order, and it catches
incorrect definitions.
Hope this helps,
Elan