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

[REBOL] Re: Object private member (was: objects: overhead, private data, naming

From: rotenca:telvia:it at: 21-Sep-2001 14:55

> Romano & Joel: > Thanks guys ! This thread is becoming _very_ interesting ;-) It does me > recall one about embedded objects a few months ago. > Let's go back to the subject of the first post (from Gregg Irwin I think) > ... > If I have understand all it has been written - which I seriously doubt ;) - > it should be possible to implement privacy in a way, using the property "use > [b][context [set 'b 4 a: 3]]" where "b is local at Use block because 'b is > NOT defined in the object" : > Isn't it the effect we were trying to reach, or did I miss something ?
Yes, you are right. You can make it with Use, like in example or with context. Here _b _print-a _print-p are not lit-word, so are not defined in the object and their words are bound to the Use block, while ctx is global because is not declared in the use block. Remark 1. If you now make: ctx2: context ctx [] ctx and ctx2 share all the privates field ('_b _print-a _print-b) while public field ('a) is not the same. The private _b... are shared by all the objects wich use ctx model (or ctx2 model an so on). Remark 2. If you do: ctx2: context ctx [_b: 0] ctx2/get-b will access always the '_b local to the use block. Remark 3. It is possible write a routine which changes the value of use _b from the inner of the object: ;public set-b: func [value][_set-b :value] .... ;private set '_set-b func [value] [set/any '_b :value] Remark 4: it is possible to write generic routines for getting/removing private values: ;private set '_set-private func [word [word!] value] [set/any bind :word '_set-private :value] set '_get-private func [word [word!]] [get/any bind :word '_get-private] then they need public stub routines. Or write routines which return by default the private value or the public if declared. I think there are few limits and that should be a good idea to write a routine which create this type of contexts: make-object: func [public [block!] private [block!] routine [block!]] it should contrust the code and Use block on the fly and execute it. --- Ciao Romano