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

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Thu Jul 9 16:18:28 EDT 2009

On Thu, Jul 9, 2009 at 4:07 PM, Grant Rettke<grettke at acm.org> wrote:
> On Thu, Jul 9, 2009 at 2:52 PM, Carl Eastlund<carl.eastlund at gmail.com> wrote:
>> You only need one apostrophe, and the result is equivalent to:
>>
>> (define foo (list 'yes 'no))
>>
>> I hope this helps.
>
> When you introduce quote to students, who do you go about doing so?

Personally?  I don't.  But then I have never taught Scheme beyond the
first semester, and there's no call for it then.  (Well, ok, for
symbols, but that's a trivial case.)

> I first read about quote in TSPL. As I recall, it follows the approach
> of visualizing the read-evaluate-print loop, and explains that quote
> roughly means that whatever follows it is the external representation
> of the thing that want, so whatever did follow will not get sent to
> the evaluator. Perhaps this is not the best summary, but whatever the
> case the explanation (in part with the whole chapter) made it easier
> to understand. That was my experience it at least.

There's two important things to learn about quote.

The first is that 'E means (quote E), for any term E.

The second is that the expression (quote E) produces E as a value,
rather than running it as code.

Following those rules, '('yes 'no) is (quote ((quote yes) (quote
no))), and it produces the value ((quote yes) (quote no)).  Apply
those two rules, and quote shouldn't have any more surprises.

Quasiquote and unquote are a bit trickier, but still follow just a few rules.

--Carl


Posted on the users mailing list.