[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why is booleanp defined this way?

From: Barry Margolin
Subject: Re: Why is booleanp defined this way?
Date: Fri, 17 Apr 2015 19:20:44 -0400
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <address@hidden>,
 Marcin Borkowski <address@hidden> wrote:

> Hi all,
> this is what I found in subr.el:
> ,----
> | (defun booleanp (object)
> |   "Return t if OBJECT is one of the two canonical boolean values: t or nil.
> | Otherwise, return nil."
> |   (and (memq object '(nil t)) t))
> `----
> Seemingly, it doesn't make much sense: what is the purpose of saying
> (and (whatever) t)
> instead of just
> (whatever)
> for a predicate?  Of course, this "normalizes" any "truthy" value to
> "t", but is it really needed for anything (except perhaps being
> elegant)?

I guess they felt that the result of booleanp should *be* booleanp. :)

While it probably doesn't matter when you're using it in a program, 
since you'll usually be using it as part of a conditional operator (if, 
cond, when), they might have felt it would be confusing when people used 
it interactively:

(booleanp nil) => (nil t)
(booleanp t) => (t)
(booleanp something-else) => nil

As a general convention, predicates usually just return t or nil, unless 
there's a useful non-nil value to return when it's true. In the case of 
memq, returning the tail of the list starting with the match was felt to 
be useful. But it's hard to see how returning those little lists instead 
of t would be helpful to anyone calling booleanp.

Barry Margolin, address@hidden
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

reply via email to

[Prev in Thread] Current Thread [Next in Thread]