[Top][All Lists]

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

Re: case syntax and symbols

From: Marius Vollmer
Subject: Re: case syntax and symbols
Date: Tue, 22 Mar 2005 01:53:33 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

Aaron VanDevender <address@hidden> writes:

> Hello,
> I have noticed that guile evaluates the following to #t
> (case 'x
>   ('x #t)
>   (else #f))
> even though R5RS section 4.2.1 seems to say that all of the statements
> (besides else) must be of the form ((datum ...) ...). Clearly the symbol
> 'x is not a list. What is going on here?

It is a bit tricky.  The syntax 'x is short for (quote x).  This
expansion is done by the reader without looking at the context.  So,
what the evaluator really sees is

  (case 'x
    ((quote x) #t)
    (else #f))

This is indeed in the form required by R5RS, although probably only by
accident.  As expected, the following also evaluates to true:

  (case 'quote
    ('x #t)
    (else #f))
  => #t

Also (and don't try this at home kids):

  (define 'x (* x x))
  => 4

GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405

reply via email to

[Prev in Thread] Current Thread [Next in Thread]