Re: Is there any eq t test in Common Lisp?



Pascal Bourguignon wrote:
"Kaz Kylheku" <kkylheku@xxxxxxxxx> writes:

On Jan 26, 6:34 am, "Andreas Thiele" <nos...@xxxxxxxxxx> wrote:
Hi,

I'm just wondering if there is no predefined synonym for

(defun t-p (x) (eq t x))?
This would be just as silly as

#define TRUE 1
#define ISTRUE(X) (X == TRUE)

in C. (See comp.lang.c FAQ's 9.2 and 9.3). Believe it or not, there are
some programmers who do this. (And I'm not talking about the lack of
parentheses in the expansion of X either; I left that bug in just to
make the example a more realistic depiction of real-world stupidity,
which is rarely found in nature as a free element, because it's
frequently compounded).

Just like the way any non-zero (or non-null) value in C serves as true,
in Common Lisp anything that isn't NIL serves as true. That's how
``generalized booleans'' work in Common Lisp, and therefore comparing a
boolean value to T is a bug.


Indeed, (eq t x) is silly. If you want to know if x is the symbol t, then you should write (eq 't x).

The constant variable t is specified to return the symbol t, (eq t x) and (eq 't x) are guaranteed to behave the same.

It is indeed the case that it can be useful to distinguish between being "just true" and "true with additional information". For example, one case where this pops up in ANSI CL itself is when you want to define methods for shared-initialize and have to distinguish the three cases for its second argument.


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
.



Relevant Pages

  • Re: Why cons *pairs*?
    ... Pascal Bourguignon wrote: ... would get called with the formal arguments 'month' and 'account' and ... In some tests I have made in several Common Lisp implementations, it was even later. ...
    (comp.lang.scheme)
  • Re: Beyond CL?
    ... >> Pascal Bourguignon wrote: ... >> dangerous to take over the ubiquitous symbol 'x'. ... Well let's consider this in both Common Lisp and T3K-Lisp. ...
    (comp.lang.lisp)
  • Re: How to write binary data to standard out?
    ... Pascal Bourguignon wrote: ... This is not supported by all stream types though: ... It's also not a part of Common Lisp, and thus unlikely to be supported ... Juho Snellman ...
    (comp.lang.lisp)
  • Re: Lisp collections
    ... Pascal Bourguignon writes: ... because you have a bug in your remove-at! ... The attributions are messed up on this message. ...
    (comp.lang.lisp)
  • Re: Format bug in CLisp?
    ... Pascal Bourguignon wrote: ... Or is it not a bug at all? ... I think it's gotta be a bug. ...
    (comp.lang.lisp)