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

[REBOL] Re: Private/Public attributes

From: ingo:2b1 at: 15-Nov-2002 23:02

Gregg Irwin wrote:
> Hi Miguel, > > ML> I want to know if the concepts of private and public are > implemented in > ML> Rebol? > > Not really; at least not in a way you might expect. As with most > things in REBOL, you can find a way though.
And as most things, you can find more than one way ... o: make object! [ ; public goes here self: make object! [ set: func [val][ private_val: val ] get: func [][ private_val ] ] ; private goes here private_val: none ]
>> probe o
make object! [ set: func [val][ private_val: val ] get: func [][ private_val ] ]
>> o/private_val
** Script Error: Invalid path value: private_val ** Near: o/private_val
>> o/self/private_val
** Script Error: Invalid path value: private_val ** Near: o/self/private_val
>> o/get
== none
>> o/set 3
== 3
>> o/get
== 3 'self is normally a pointer to the object! itself, so by setting it to some other value, the object! does not point to itself anymore - or something like that. I don't know, if there may be some problems with the garbage collector, though. Kind regards, Ingo