true function

Discussion of Common Lisp

true function

Postby 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.
stackman
 
Posts: 28
Joined: Sat Oct 06, 2012 5:44 am

Re: true function

Postby nuntius » Sun Oct 07, 2012 9:39 am

(some 'identity list) ?
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: true function

Postby 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.
stackman
 
Posts: 28
Joined: Sat Oct 06, 2012 5:44 am

Re: true function

Postby 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).
User avatar
Goheeca
 
Posts: 214
Joined: Thu May 10, 2012 12:54 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 3 guests

cron