Reflection and quotation
Jecel Assumpcao Jr
jecel@tunes.org
Wed, 23 Aug 2000 17:34:42 -0300
I have not really followed all this discussion, but like Faré I will
make a comment on the original question.
Here is an example of why I got lost in the discussion:
On Wed, 23 Aug 2000, Kyle Lahnakoski wrote:
> You want to edit 4? What would you like to do to it? This weaving of
> behavior and objects is a side effect of not having a normalized
> representation of that specific domain. If 4 has attributes, like
> behavior, then somebody did bad design work.
In object oriented programming the number 4 typically has behavior (you
can ask it for its successor and get 5 as an answer, for example). You
might not like it, but I don't see how you can declare it as "bad
design".
Back to Lisp: my impression from doing a few implementations of the
language is a little different from Faré's QUOTE, EVAL, KWOTE,
QUASIQUOTE, UNQUOTE theory. I simply tagged a defined lambda associated
with some symbol as either an EXPR or a FEXPR. EVAL checked this and
called itself recursively for the arguments in the first case but
passed on the arguments unchanged for the second. This would allow use
to have quote a normal FEXPR instead of a special form:
(defun QUOTE fexpr (lambda (x) x))
or something like that. Of course, you need some help from the parser
to have the ' style of quotes, but if EVAL knows about FEXPRs it
doesn't have to know about QUOTE.
Here is an interesting (but badly formatted) Lisp history (which has
QUOTE as a special form in all examples):
http://www8.informatik.uni-erlangen.de/html/lisp/mcc91.html
In any case, Alan Kay didn't like any of the solutions adopted in Lisp
and tried to come up with a language that would solve the quoting
problem in a more elegant way. That was Smalltalk-72. In that language,
each class had a single piece of code which would parse the "message
stream" as it executed. That allowed each class to define a totally
different syntax, which was very fun but ended up causing a lot of
communications problems between programmers. Among the special
functions that could be used by a class code were:
eyeball: checks that the next symbol in the message stream is a given
one. Returns true and consumes the symbol if yes, returns
false otherwise.
colon: evaluates the next expression in the stream and returns it.
open-colon: returns the unevaluated next expression. You can call
EVAL on it later.
I guess he felt that having the colon/open-colon choice for each
argument was more interesting than a hidden EXPR/FEXPR attribute. On
ther other hand, Smalltalk-72 also had a ' quotation mechanism that was
hardwired into EVAL.
The problem with all these choices is that looking at the sender side
of the message stream you can't tell if an expression will be passed
evaluated or not. Dan Ingalls introduced a fixed syntax system in
Smalltall-76 and in Smalltalk-78 cleaned up the quoting problem for
expressions by introducing the square bracket notation for block
objects. Now it was the sender who decided whether an expression should
be evaluated before or after being bound to an argument:
xxx ka: (2+2) "evaluate"
xxx kb: [2+2] "do not evaluate"
which would be something like (ka xxx (+ 2 2)) and (kb xxx '(+ 2 2)) in
Lisp. In fact, Logo uses parenthesis for evaluated lists and square
brackets for quoted ones too. Note that numbers and a few other types
of objects are self quoting, but that is easily handled by patching
EVAL and I won't mention it further.
In Self it is defined that anytime you reference a method object, it is
evaluated and the result is returned instead of the object. This means
that no expression can ever return a method object directly. Mirror
objects help solve this problem since anything you might be interested
in doing to a method object you can ask its mirror to do it for you. An
alternative design would be to have different slot types, so that
a method object in one type would auto evaluate while the same object
stored in another slot type would not (allowing you to refer to it
directly). Self's designers didn't like this idea very much.
While mirrors are doing double duty in Self (reflection and quotation),
I am not sure there is any relation between the two concepts.
-- Jecel