true function

Discussion of Common Lisp
Post Reply
stackman
Posts: 28
Joined: Sat Oct 06, 2012 5:44 am

true function

Post by stackman » Sat Oct 06, 2012 6:23 am

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.

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: true function

Post by nuntius » Sun Oct 07, 2012 9:39 am

(some 'identity list) ?

stackman
Posts: 28
Joined: Sat Oct 06, 2012 5:44 am

Re: true function

Post by stackman » Mon Oct 15, 2012 8:50 am

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.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: true function

Post by Goheeca » Mon Oct 15, 2012 9:07 am

It doesn't mind because in CL everything is a true value but nil.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Post Reply