Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does common lisp's case construct always match True (T)?

This is with SBCL 1.0.55 on Debian squeeze. I'm probably missing something obvious, but I'm a beginner, so please bear with me.

CL-USER> (defparameter x 0)

CL-USER> (case x (t 111) )
111

So it looks like case here is matching the variable x with the truth symbol t. This happens with everthing I've tried; this x is just an example. I don't see why this would happen. Since case uses eql for matching, I tried

CL-USER> (eql x t)
NIL

So, eql does not match x and t. What am I missing? Thanks in advance.

like image 402
Faheem Mitha Avatar asked Mar 18 '12 15:03

Faheem Mitha


2 Answers

In the case construct in Common Lisp, t, used by itself, is equivalent to default in C; that is, it's evaluated if the expression doesn't match any of the other cases. If you want to match the actual symbol t, use (t) instead.

like image 41
Taymon Avatar answered Oct 06 '22 16:10

Taymon


Described in the CASE documentation.

otherwise-clause::= ({otherwise | t} form*)

The syntax says that an otherwise clause is either (otherwise form-1 ... form-n) or (t form-1 ... form-n). Note that the syntax says {otherwise | t}. The vertical bar is an OR in a syntax specification. So the marker for an otherwise clause is either otherwise or t.

That means, if your case clause begins with otherwise or t, then we have an otherwise-clause.

like image 50
Rainer Joswig Avatar answered Oct 06 '22 15:10

Rainer Joswig