Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Private Object Function

From: rebol:techscribe at: 17-Jan-2001 11:43

Hi Christophe,
> > Hidden objects or contexts are not protected from descendants. > [Do you mean by this it shouldn't be possible to implement it in > REBOL ?]
No, I mean that using REBOL's default inheritance mechanism, i.e.
>> o: make object! [foo: none make object! [bar: does ["I'm hidden"] set 'foo does [bar] ] ] >> p: make o [foobar: "I'm p"]
p will have inherited foo as a functions that successfully calls bar just like o does. This leads to the following situation. Given:
>> o: make object! [
foo: none set-bar: none make object! [ bar: none set 'foo does [bar] set 'set-bar func [value] [ bar: value ] ] ]
>> p: make o [] >> o/set-bar "I was set by o." >> print ["o/foo" mold o/foo]
o/foo "I was set by o."
>> print ["p/foo" mold p/foo]
p/foo "I was set by o."
>> p/set-bar "I was set by p." >> print ["o/foo" mold o/foo]
o/foo "I was set by p."
>> print ["p/foo" mold p/foo]
p/foo "I was set by p." Note that - unlike your requirements for private values - p and o share o's private value bar. REBOL's inheritance mechanism acts in a protected way with respect to children's access to hidden object properties. This means that you should really implement your own custom object mechanism, let's call it class mechanism to separate it from REBOL's objects, which may be built on top of objects. class!: make object! [ private: none published: none public: none ] some-class: class class! [ private [ pa: none pb: none ] published [ ua: none ub: none ] public [ la: none lb: none ] ] class: func [ spec [block!] /local new-class] [ set [_ private-block _ published-block _ public-block] spec return make object! [ private: make object! private-block published: make object! published-block public: make object! public-block ] ] some-child: clone some-class clone: func [parent [object!] /local result] [ ; has to be written. I don't have the time right now. ; what takes a little more time is that you must account ; for possible complex structures such as classes embedded ;in a class, or blocks of objects/classes embedded ... ; If nothing useful pops up on the mailing list perhaps I'll implement something this evening ]
> BTW is there anybody interested by the results I will get ? I do not > want to spam the list with uninteresting stuff...
Well, as you've guessed by now, I'd even be interested in contributing some code. I think it'd be an interesting ongoing public project. Take Care, Elan