Re: (case 'quote ('lambda 1) (otherwise 2))




David Wragg wrote:
I have found 2 Common Lisp implementations that think that the above
code evaluates to 1. This is quite surprising to me.

SBCL 1.0.2 (on Fedora Core 6 x86-64, from the extras repository)
* (case 'quote ('lambda 1) (otherwise 2))
[...]
1

CLisp 2.41 (as above):
[1]> (case 'quote ('lambda 1) (otherwise 2))
1

Both implementations give less surprising results for (eq 'quote
'lambda) and (case 'lambda ('quote 1) (otherwise 2)).

Is this the correct behavior (and if so, where should I look in the
Hyperspec to understand it)? Or do these independent implementations
share an obscure bug?

I think that the correct behavior, and should evaluate to 1 on all
Common Lisp systems. "case" doesn't evaluate its "key" arguments. So
'lambda is the same as the two element list (quote lambda). Compare
to...

(case 'quote
((lambda quote) 1)
(otherwise 2))

....which also evaluates to 1. You might also want to study these
examples...

(case 'foo
((foo bar baz) 1)
(otherwise 2))

(case 'bar
((foo bar baz) 1)
(otherwise 2))

.



Relevant Pages

  • Re: COBOL to Java conversion
    ... surprising that it does it poorly; what is surprising is that it would want ... Samuel Johnson quote? ... "Never try to teach a pig to sing. ...
    (comp.lang.cobol)
  • Re: COBOL to Java conversion
    ... surprising that it does it poorly; what is surprising is that it would want ... Samuel Johnson quote? ... ursines all I can remember is 'The miracle of a dancing bear is not how ... gracefully it dances, but that it dances at all.' ...
    (comp.lang.cobol)
  • Re: Detecting type of object
    ... es committee realized that limiting host objects ... I'm not sure that such limitation is a good thing. ... It makes current implementations non-conforming. ... You quote them as saying: ...
    (comp.lang.javascript)
  • Re: (case quote (lambda 1) (otherwise 2))
    ... Both implementations give less surprising results for (eq 'quote ... 'X and #'X instead of printing them as normal lists. ... The keys you gave in your first clause is (QUOTE ...
    (comp.lang.lisp)
  • Re: (case quote (lambda 1) (otherwise 2))
    ... I have found 2 Common Lisp implementations that think that the above ... This is quite surprising to me. ... So (quote quote) is evaluated to produce the symbol quote. ... symbols t and otherwise may not be used as the keys designator. ...
    (comp.lang.lisp)