[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 09:42:21 EDT 2009

On Thu, Jul 9, 2009 at 11:07 PM, Stephen Bloch<sbloch at adelphi.edu> wrote:
>
> On Jul 9, 2009, at 7:53 PM, Marco Morazan wrote:
>
>>>> ((quote yes) (quote no))
>>>>
>>>> is not a value. It is an application expression.
>>>
>>> It most certainly is a value.  It is a list of two elements.
>>
>> Huh? Really? How do you figure it evaluates to a list with two
>> elements?
>
> Note the change in wording, from "It is a list of two elements" to "it
> evaluates to a list with two elements."  Very different things.
>
> ((quote yes) (quote no))
>
> is a list with two elements, each of which is a list with two elements.
>

It is a shame that quote is ommitted by the print part of the repl.
Two identical expressions can be interpreted by those beginning as two
different things. Think about it carefully, is ((lambda  (x) (+ x 1))
4) a list or an application expression? What does Scheme syntax say?
In order to be a list you need to quote it. Ditto on the above.



>> ((quote yes) (quote no))
> (cons (cons 'quote (cons 'yes empty)) (cons (cons 'quote (cons 'no empty)) empty)

Welcome to DrScheme, version 4.2 [3m].
Language: Beginning Student; memory limit: 128 megabytes.
> ((quote yes) (quote no))
function call: expected a defined name or a primitive operation name
after an open parenthesis, but found something else
>


Welcome to DrScheme, version 4.2 [3m].
Language: Beginning Student with List Abbreviations; memory limit: 128
megabytes.
> ((quote yes) (quote no))
function call: expected a defined name or a primitive operation name
after an open parenthesis, but found something else
>

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. I think that it is best to tell students
that the above is an application expression, because it is not quoted
and that by convention Scheme does not output application expressions
and, therefore, ommits the quote for lists. The value of an expression
is ALWAYS what it evaluates to regardless of the printing convention
used.

-- 

Cheers,

Marco


Posted on the users mailing list.