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

[REBOL] Re: Private words in objects?

From: tim-johnsons::web::com at: 6-Jul-2006 13:30

* Gabriele Santilli <gabriele-colellachiara.com> [060706 01:14]:
> Hi Gregg, > > On Wednesday, July 5, 2006, 6:16:09 PM, you wrote: > > GI> You *can* do it today, but it takes extra effort. I thought I would do > GI> it a lot, once I figured out how (with the help of people here), but > GI> I've never used it in a production system. > > The way Gregg is mentioning is just using a "hidden" context for > your "protected" words. > > Example: > > use [private-field] [ > private-field: 2 > my-obj: context [ > public-field: 1 > set-field: func [val] [ > private-field: val > ] > get-field: does [ > private-field > ] > ] > ]
This is very 'use'ful to know! FYI: this is like the lisp use of 'let in the "upper level" Greg should put it in the cookbook..
> The disadvantage is that you can't easily clone the object (that > wouldn't clone the other context, so that would be shared by all > clones), so you need a constructor function. However there is no > way for you to change PRIVATE-FIELD by mistake. > (Note that there are many ways to achieve this result, so it > really depends on what's best in your specific case.)
It would be interesting to see other examples. cheers tim -- Tim Johnson <tim-johnsons-web.com> http://www.alaska-internet-solutions.com