[REBOL] Re: Private words in objects?
From: gabriele::colellachiara::com at: 6-Jul-2006 11:05
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.
use [private-field] [
my-obj: context [
set-field: func [val] [
get-field: does [
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.)
Gabriele Santilli <gabriele-rebol.com> --- http://www.rebol.com/
Colella Chiara software division --- http://www.colellachiara.com/