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

[REBOL] Re: Dumb newbie Rebol question

From: nitsch-lists:netcologne at: 5-Sep-2003 18:36

Am Freitag, 5. September 2003 05:01 schrieb Brian Parkinson:
> Wow - help on this list is great. > > Having fun putting together the X.10 control stuff - will soon be able > make available sample Rebol code to control X.10 lights - reading up on > dialects right now. Cooooool. > > But have a couple 00 questions: > > 1. Data encapsulation - is there any convenient way to make data > readonly in an object? I need to define some constants, and I want to > put them in an object so as to not clutter up the namespace. I thought > this might work, but it does not: > > x: make object! [ > a: 13 > protect 'a > ] >
see below. And as Gregg said, if you need enums, use words directly :)
> 2. Any way to enforce some sort of Singleton idiom? I suspect that > asking this (and perhaps the above) are caused by not enough > indoctrination to the Rebol way of doing things, but wondering... I am > going to put the serial connection code into an object (again, keep > namespaces clean) and in Java, I'd make this a Singleton, as I only > want one serial connection open. Not sure how this should be tackled in > Rebol. >
rebol-objects are singletons. its possible to make them "multitons" to. the "class-declaration" itself is a usable object. thats the something: context[..] is a shortcut for something: make object![..] for constant-checking, since 'protect is broken, you could check often: constants: context[a: 1 b: 2] constants-backup: make constants [] constants/a: 3 if (third constants) <> third constants-backup [alert "changed!"] wrap the last line in a function and call it often.
> Hot dang - this is a fun language! >
!!! :)
> Cheers, > > parki... >
-Volker