On 1 December 2010 10:25, Daniel Weinreb <dlw@itasoftware.com> wrote:
Here is a way that CL sucks badly: protocols are not first-class entities.
To modify a protocol is something done to the source code *outside* of the
Lisp world. It cannot be done programmatically.
Adherence to the protocol cannot be enforced.
Discrepancies cannot be detected.
I agree.
In Racket, for instance, modules are first-class (at syntax expansion time)
and units are first-class (at runtime), and you can manipulate them
programmatically.
First, a common base class can provide implementations of some of the
generic functions all by itself. My favorite simple example is an
"output stream" protocol, that has a write-character operation and a
write-string operation. The common base class provides an
implementation of write-string that works by iterating over the
characters of the string and calling write-character. Any output
stream that can write strings in a more efficient way can override
that method.
In my "pure" datastructure library (currently part of fare-utils,
to be spun off as lil - lisp interface library), I use mixins to
provide these "methods". So instead of adding the method to a base class,
I would provide a mixin "write-string-from-write-char", and
then could possibly add an opposite mixin "write-char-from-write-string",
without creating a paradox that will byte you.
That's good. The usual abstract base class provides
This is not perfect. A programmer might just happen to create a
vector and put one of those keywords into the +fhash-kind+ slot.
(+fhash-kind+ is zero but that's a mere detail.) But it's sort of
good enough.
Solution: don't use keywords, but private symbols. Unlike keywords,
private symbols are private. They can be faked, but not accidentally.
CL doesn't allow you to easily define sublanguages
in which things cannot be faked. That's painful.
Yes, I agree with you and Peter. Definitely.