[plt-scheme] Why isn't the car of a list of symbols a symbol?

From: Marco Morazan (morazanm at gmail.com)
Date: Fri Jul 10 13:33:12 EDT 2009


IMHO, calling ((quote yes) (quote no)) a list is confusing for
beginning students. You can not use it as a list in a program unless
you slap with an annotation (i.e. a quote). So, in a program you argue
it is an application expression and everywhere else students must
consider it a list? Frankly, that is adding an unnecessary level of
complexity. We should not have to imagine a repl without the e.

> No question: Scheme syntax says it's a list (or, technically, a syntax
> object, i.e. a list with decorations).

I have not reviewed the parser used by DrScheme, but I would be very
surprised if ((quote yes) (quote no)) is parsed as a list. In every
parser I have  ever written and seen it would parse as an application
expression. That is, the concrete syntax may have it look like a list,
but in the abstract syntax and in reality it is not a list.

> Absolutely... but let's not equate "an expression" with "the value of an
> expression".  (* 1 2 3) and (- 10 4) are completely different syntactic
> expressions

Let's not equate an expression with a list. (* 1 2 3) and (- 10 4) are
both application expressions. That is, they form instances of the same
syntactic category. One *could* use a list to represent them
internally, but that is usually not the case. In any case, in a Scheme
*program* they are application expressions regardless of how they are
represented internally.

>> In the two student languages you mention when you ask what is ((quote
>> yes) (quote no)), you can see that Scheme considers it an application
>> expression. It is the *human* interpreter that introduces ambiguity by
>> interpreting it as a list.
> What exactly do you mean by "Scheme considers it..."?  The "read" part of
> the read-eval-print loop has never heard of an "application expression"; it
> converts a string into (to a first approximation) a list.  Only the "eval"
> part considers it an application expression.

Usually, the input is read and parsed resulting in a parse tree. In
this parse tree, ((quote yes) (quote no)) is an application
expression. This all occurs *before* eval comes into the picture. So,
that explains what I mean by "considers it." You may argue that a
parse tree can beimplemented using lists, but that representation (or
any other) is inconsequential as to what ((quote
yes) (quote no)) is. It is an application expression and it is not a
list which would require a quote.




Posted on the users mailing list.