From: ·······@my-dejanews.com
Subject: simple query about implemnting data hiding
Date: 
Message-ID: <7h1a6v$b2c$1@nnrp1.deja.com>
Hi

I'm working my way through On Lisp by Paul Graham, as a student I've been
shoved in the deep end without going through the beginnings and am having
trouble trying to extend a small part of the Object system he creates to
provide data encapsulation.  In a nutshell heres what I'm doing.  All methods
and data are stored in a symbol using hash-tables.  i.e. we can store a
property using (setf (gethash 'color obj1) 'red).  We can then access these
properties easily using just gethash by itself.  So far so good but I want to
be able to define a property of an object as only being accessible to methods
that have also been assigned to the object.
i.e. I only want functions that have been hashed into the symbol having access
to certain properties.

for example i have a hash-value of a symbol obj1 which is the symbol y, the
symbol y is private.  Then if I go (funcall(gethash 'operation_on_y obj1)obj1
10) it will work and return a answer.  But if I try and access the property
directly like (gethash 'y obj1) then it will return nil because I can't access
it directly becuase its a private symbol.

I hope I'm clear enough to be understood, this is all new for me.  I'm reading
a advanced book on lisp after being introduced to the language a little over 2
weeks ago.....arrrgh ;-(

I've had a look at labels and closures but I don't think that there what I
want.

Can someone just point me in the right direction at least. Like most students
I'm juggling a pile of assignments at once and a little direction would make
my life a lot easier.

Thanks heaps
Jason

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
From: Stig Hemmer
Subject: Re: simple query about implemnting data hiding
Date: 
Message-ID: <ekvk8uj2z0o.fsf@kallesol.pvv.ntnu.no>
> Can someone just point me in the right direction at least.

[Side note: There should be somebody associated with the course whose
 job is to point students in the right direction]

Well, one possible suggestion would be to use something other than the
symbol for a hash key.  The "priviliged" methods must then be told how
to find the real hash key.

You can get hash keys from the standard function GENSYM.

There are several ways you can 'tell' the priviliged methods which
hash key to use, I haven't seen the rest of Grahams object system, so
I don't know which one fits in the best.

Stig Hemmer,
Jack of a Few Trades.