[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

quote



This is a comment on Sanji Narain's response to Paul Hudak's response
to his remark about quote:

    The question I asked is not as trivial as it sounds to people who
    seem to have objected to it. It has to do with the necessity of quoting
    expressions, something which is absent from other systems such as Prolog.

    Hudak made the mysterious comment that Scheme/T doesn't need
    to quote either. Well, if you want to set x to the symbol a try typing
    (set x a). In Prolog you can do X=a quite legitimately. The problem
    is simply that in Lisps there is no way of distinguishing variables from
    constant symbols of the same name. So, you must use quote.

This is an important issue that is very much misunderstood.

Lisp chooses to blur the line between data structures that can be
manipulated, and expressions in the language itself.  The reason for
doing this is that it leads to increased programming power.  For
instance, one could make a pattern matcher in which various elements
of the patterns are simply (names of) Lisp procedures, thus leading to
ability to explicitly EVAL parts of the pattern.

If one wanted to give up this power, then one could choose essentially
any ad hoc way to distinguish expressions from data (e.g., one could
capitalize all identifiers, as does Prolog).  Thus, in Prolog, one can
unambiguously write X=a (as Narain points out) but one cannot
unambiguously write X=Y, if the intent of this is to assign to X a
constant (written as Y), which is later to be assembled into a data
structure that is to be later interpreted as a Prolog program with an
identifier named Y.

Of course, there is nothing to stop one from writing a Prolog
evaluator in Prolog (and there are good reasons for doing so) but then
the quotation problem (distinguishing expressions in the Prolog that
is performing the evaluation from expression in the Prolog that is
being evaluated) arises just as it does in Lisp.

This is not to say that Lisp's (or Scheme's) treatment of quote is the
last word in handling this problem.  See Brian Smith's thesis for an
alternative, and perhaps more consistent approach.

A couple of people have suggested to Sussman and me that we give up
using quote in our book, since it would make things easier for
students, and also make a simpler language from a theoretical point of
view.  Our opinion is that quote (hence the ability to mix data and
expressions) provides a real source of power that is intimately
related to Lisp's ability to serve as an implementation vehicle for
embedded languages and programming environments.  But we do make this
point in our book.

It would be nice to assemble a collection of good examples that use
quote in this way.

Note that the same issues underly the use of macros.  Contrary to what
Narain asserts, macro expansion is not just lambda reduction.  This is
true for SOME macros (like defining IF in terms of COND) but not true
for others (such as DO) where the elements of the from may not even be
syntactically valid Lisp (or Scheme) expressions.