[REBOL] Re: Dumb newbie Rebol question
From: andrew:martin:colenso:school at: 5-Sep-2003 15:19
parki wrote:
> 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
> ]
Can't really make a value read-only in a object in Rebol. But this kind
of thing might be helpful:
>> use [x_a] [
[ x_a: 123
[ x: make object! [
[ a: does [x_a]
[ ]
[ ]
>> probe x
make object! [
a: func [][x_a]
]
>> x/a
== 123
>> x_a
** Script Error: x_a has no value
** Near: x_a
Note that 'x_a and it's value are not (easily) accessible outside the
object. This kind of thing can be helpful in making only one of a thing,
by making the value of 'x_a an object! inside the object referred to by
'x.
Andrew J Martin
Attendance Officer &
Information Systems Trouble Shooter
Colenso High School
Arnold Street, Napier.
Tel: 64-6-8310180 ext 826
Fax: 64-6-8336759
http://colenso.net/scripts/Wiki.r?AJM
http://www.colenso.school.nz/
> -----Original Message-----
> From: Brian Parkinson [mailto:[parki--whatevernot--com]]
> Sent: Friday, September 05, 2003 3:01 PM
> To: [rebol-list--rebol--com]
> Subject: [REBOL] Re: Dumb newbie Rebol question
>
> 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
> ]
>
> 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.
>
> Hot dang - this is a fun language!
>
> Cheers,
>
> parki...
>
> >
> >> Time to step up the learning curve (it seems, well, so
> *weird* from a
> >> Java/C perspective :-) :-) :-)
> >
> > Yes, very different from some compiled languages!
> >
> > You might find something of interest here:
> > http://www.codeconscious.com/rebol/articles/rebol-concepts.html
>
> --
> To unsubscribe from this list, just send an email to
> [rebol-request--rebol--com] with unsubscribe as the subject.
>
DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally
liable) for materials distributed to or acquired from user e-mail accounts. You can report
any
misuse of an e-mail account to our ICT Manager and the complaint will be investigated.
(Misuse can come in many forms, but can be viewed as any material sent/received that
indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate
language and/or other issues described in our Acceptable Use Policy.)
All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0
Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]