Juanjo Garcia <
kod...@gmail.com> writes:
> Correct me if I'm wrong:
>
> In Common Lisp, encapsulation is considered
> as a concept completely independent from the
> object system.
>
> There are 2 ways of getting encapsulation,
> one is by using the package system and
> the other is by using closures.
FSVO "encapsulation". And also uninterned symbols.
Ie. the point is that in a highly introspective system (and CL is not
very introspective actually, other lisps, or implementations may be way
more introspective), encapsulation is just lip service.
So CL recognize it, and doesn't provide any feature to _enforce_
encapsulation: this is archived only by way of convention and programmer
discipline.
Nothing prevents you to write:
(list (pack:method obj (pack:public-accessor obj))
(pack::protected-method? obj (pack::protected-accessor other-obj))
(pack::%private-method?? obj (slot-value other-obj 'pack::%private-slot)))
Eg. while CL doesn't provide any way to introspect a closure,
implementation may provide some way, in particular with their debugger.
So it's only programmer discipline (or ignorance) that prevents access
to the enclosed bindings. Or the garbage collector could provide a
function to scan all the live objects on the heap, which would include
uninterned symbols. Or you coul have access to low-level pointers and
scan the memory yourself. etc.
> From time to time, I see lispers
> (even notable ones like Greenblat)
> confused by other cultures unfounded
> prejudice that they must be related concepts.
Definitely. In Modula-2, encapsulation is provided by modules, and
there's no classes or objects. There is Modula-3 which provides classes
and objects, but still uses modules to encapsulate, ie. to allow access
to exported symbols and prevent access to internal symbols. Same with
Object Pascal which distinguishes classes and units.
--
__Pascal Bourguignon__
http://www.informatimago.com/
A bad day in () is better than a good day in {}.