Page 1 of 1

true function

Posted: Sat Oct 06, 2012 6:23 am
by stackman
Hi,

is there a "true" function in Common Lisp ?
I mean does there exist a function that returns t for all non nil values of its argument,
and nil if its argument is nil?

There are at least two "false" functions, not and null, which are strictly equivalent, but I was not able
to locate a "true" function. Some context: i want to write an expression that takes a list as its argument,
returns t if there is a non-nil element in the list, and nil otherwise. Here is what I have at the moment.

Code: Select all

(notevery 'not list)
The not-not looks weird though. With a true function, I could write (some 'true list), which seems cleaner.

Re: true function

Posted: Sun Oct 07, 2012 9:39 am
by nuntius
(some 'identity list) ?

Re: true function

Posted: Mon Oct 15, 2012 8:50 am
by stackman
This does not give exactly the same result.

Code: Select all

CL-USER> (some 'identity (list nil "no" nil))
=> "no"
CL-USER> (notevery 'not (list nil "no" nil))
=> T
So I guess there is no builtin true function.
Anyway, thanks for the answer.

Re: true function

Posted: Mon Oct 15, 2012 9:07 am
by Goheeca
It doesn't mind because in CL everything is a true value but nil.