From: ssecorp
Subject: how to check if a list is empty or nil?
Date: 
Message-ID: <8ef28f1e-2d71-482d-9e6c-10c18407a5b8@m73g2000hsh.googlegroups.com>
(not (= lst nil))

(/= lst nil)

empty?, list?, nil? does not work either.

do I really have to use (= 0 (length lst))
seems inefficient if the lists can be big.

From: Brian
Subject: Re: how to check if a list is empty or nil?
Date: 
Message-ID: <1a389632-aa9d-4001-8ef7-2a48ce572c49@k13g2000hse.googlegroups.com>
On Aug 23, 10:59 am, ssecorp <············@gmail.com> wrote:
> (not (= lst nil))
>
> (/= lst nil)
>
> empty?, list?, nil? does not work either.
>
> do I really have to use (= 0 (length lst))
> seems inefficient if the lists can be big.
Use NULL.  ENDP also works.
From: Chris Russell
Subject: Re: how to check if a list is empty or nil?
Date: 
Message-ID: <6eaec756-6e83-4f9d-9a89-b5b1b446e1fe@m44g2000hsc.googlegroups.com>
On 23 Aug, 16:59, ssecorp <············@gmail.com> wrote:
> (not (= lst nil))
>
> (/= lst nil)
>
> empty?, list?, nil? does not work either.
>
> do I really have to use (= 0 (length lst))
> seems inefficient if the lists can be big.

The empty list is false so you can write

(if list
    (do stuff);non-empty case
    (do other stuff));empty case

Otherwise do what Barry says.
From: Kenny
Subject: Re: how to check if a list is empty or nil?
Date: 
Message-ID: <48b038e1$0$7341$607ed4bc@cv.net>
ssecorp wrote:
> (not (= lst nil))
> 
> (/= lst nil)
> 
> empty?, list?, nil? does not work either.
> 
> do I really have to use (= 0 (length lst))
> seems inefficient if the lists can be big.

lst. Or list if you realize you are not doing scheme.

kt
From: ssecorp
Subject: Re: how to check if a list is empty or nil?
Date: 
Message-ID: <11dd62ce-211c-4d94-b3b8-f6e3bc5cf752@x41g2000hsb.googlegroups.com>
On Aug 23, 6:19 pm, Kenny <·········@gmail.com> wrote:
> ssecorp wrote:
> > (not (= lst nil))
>
> > (/= lst nil)
>
> > empty?, list?, nil? does not work either.
>
> > do I really have to use (= 0 (length lst))
> > seems inefficient if the lists can be big.
>
> lst. Or list if you realize you are not doing scheme.
>
> kt

huh?
From: DeverLite
Subject: Re: how to check if a list is empty or nil?
Date: 
Message-ID: <a0110415-d652-44d7-8d22-cf82da78cdfc@x35g2000hsb.googlegroups.com>
On Aug 23, 11:42 am, ssecorp <············@gmail.com> wrote:
> On Aug 23, 6:19 pm, Kenny <·········@gmail.com> wrote:
>
> > ssecorp wrote:
> > > (not (= lst nil))
>
> > > (/= lst nil)
>
> > > empty?, list?, nil? does not work either.
>
> > > do I really have to use (= 0 (length lst))
> > > seems inefficient if the lists can be big.
>
> > lst. Or list if you realize you are not doing scheme.
>
> > kt
>
> huh?

I think Kenny's point is that you can use the name "list" rather than
"lst", and this will not conflict with the function (named "list")
because, unlike scheme, CL has a separate namespace for functions.
From: Pascal J. Bourguignon
Subject: Re: how to check if a list is empty or nil?
Date: 
Message-ID: <87ej4fwoo6.fsf@hubble.informatimago.com>
DeverLite <············@gmail.com> writes:

> On Aug 23, 11:42�am, ssecorp <············@gmail.com> wrote:
>> On Aug 23, 6:19�pm, Kenny <·········@gmail.com> wrote:
>>
>> > ssecorp wrote:
>> > > (not (= lst nil))
>>
>> > > (/= lst nil)
>>
>> > > empty?, list?, nil? does not work either.
>>
>> > > do I really have to use (= 0 (length lst))
>> > > seems inefficient if the lists can be big.
>>
>> > lst. Or list if you realize you are not doing scheme.
>>
>> > kt
>>
>> huh?
>
> I think Kenny's point is that you can use the name "list" rather than
> "lst", and this will not conflict with the function (named "list")
> because, unlike scheme, CL has a separate namespace for functions.

No. Kenny's point is that to test for a not null list you can just
write list.  In the same way that in C, to test for a non zero integer
you can just write integer.


And the OP should try reading some initiation book about Common Lisp,
like:

    Common Lisp: A Gentle Introduction to Symbolic Computation
    http://www-cgi.cs.cmu.edu/afs/cs.cmu.edu/user/dst/www/LispBook/index.html
    http://www.cs.cmu.edu/~dst/LispBook/


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Kitty like plastic.
Confuses for litter box.
Don't leave tarp around.
From: Kenny
Subject: Re: how to check if a list is empty or nil?
Date: 
Message-ID: <48b0620a$0$7362$607ed4bc@cv.net>
ssecorp wrote:
> On Aug 23, 6:19 pm, Kenny <·········@gmail.com> wrote:
> 
>>ssecorp wrote:
>>
>>>(not (= lst nil))
>>
>>>(/= lst nil)
>>
>>>empty?, list?, nil? does not work either.
>>
>>>do I really have to use (= 0 (length lst))
>>>seems inefficient if the lists can be big.
>>
>>lst. Or list if you realize you are not doing scheme.
>>
>>kt
> 
> 
> huh?

1. nil is false
2. there is no need to mangle the name
3. 1 and 2 are false in Scheme

kt
From: Barry Margolin
Subject: Re: how to check if a list is empty or nil?
Date: 
Message-ID: <barmar-79F766.13022523082008@newsgroups.comcast.net>
In article 
<····································@m73g2000hsh.googlegroups.com>,
 ssecorp <············@gmail.com> wrote:

> (not (= lst nil))
> 
> (/= lst nil)

= and /= are for numbers.  EQ is the predicate you should use if you 
want to compare with NIL.

> 
> empty?, list?, nil? does not work either.

Others have mentioned NULL.  There's also NOT (although that should 
generally only be used when you're treating it as a boolean, rather than 
a list) and ENDP (which is generally used when you're iterating, hence 
the name).

> 
> do I really have to use (= 0 (length lst))
> seems inefficient if the lists can be big.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***