[plt-scheme] Expansion of `case' in context with `else' bound

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Oct 31 17:42:05 EST 2006

On Oct 31, Casey Klein wrote:
> The expansion of the expression 
>    (let ([else #f]) (case 'foo [else 42])) 
> fails with the error "case: bad syntax (not a datum sequence) in:
> else."
> Is there a reason that a binding for the `else' identifier here must
> prevent the use of an "else clause" in a case expression?

Consider the same with `cond':

  (let ([else #f]) (cond ... [else 42]))

In mzscheme, the local binding overrides the keyword.  This is a
result of comparing identifiers rather than the symbol that was used
in the source.

> If the definition of case is comparing the binding of the provided
> `else' to its own, could it instead simply check for symbol
> equality?

It could for `case' -- but I think that it makes sense to treat it in
the same way as `cond'.

> Incidentally, where can I find the definition of the case macro?

Looks like it's part of the core, not defined in Scheme.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.