Why does the general case lisp constructor always match True (T)?

This is with SBCL 1.0.55 when compressing Debian. I probably missed something obvious, but I'm a newbie, so please bear with me.

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

So, it looks like the case here corresponds to the variable x with the true symbol t . This happens with everything I've tried; this x is just an example. I do not understand why this will happen. Since case uses eql for matching, I tried

 CL-USER> (eql xt) NIL 

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

+4
source share
2 answers

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

+6
source

Described in the CASE documentation.

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

The syntax says that otherwise the sentence is either (otherwise form-1 ... form-n) or (t form-1 ... form-n) . Note that the syntax says {otherwise | t} {otherwise | t} . The vertical bar is an OR in the syntax specification. Thus, the token for the else clause is otherwise or t .

This means that if your case clause starts with otherwise or t , then we have otherwise-clause .

+6
source

Source: https://habr.com/ru/post/1402108/


All Articles