From: Eric Strudel
Subject: Newbie: Quick Question regarding Disassembling a list
Date: 
Message-ID: <avfkc.6465$184.4796@fe08.usenetserver.com>
Hello,

If I have a list say (setq list1 '(T T T T NIL)), is there a way to
disassemble that list into individual atoms without using a loop so that I
can do a binary AND for them?

For example, (and (T T T T NIL)) gives me NIL, but how can I access the (and
list1) so it will give me NIL as well?  Thanks!

From: pkhuong
Subject: Re: Newbie: Quick Question regarding Disassembling a list
Date: 
Message-ID: <51184814.0404291759.62f7965b@posting.google.com>
"Eric Strudel" <··········@hotmail.com> wrote in message news:<···················@fe08.usenetserver.com>...
> Hello,
> 
> If I have a list say (setq list1 '(T T T T NIL)), is there a way to
> disassemble that list into individual atoms without using a loop so that I
> can do a binary AND for them?
> 
> For example, (and (T T T T NIL)) gives me NIL, but how can I access the (and
> list1) so it will give me NIL as well?  Thanks!

apply http://www.lispworks.com/reference/HyperSpec/Body/f_apply.htm
or
funcall http://www.lispworks.com/reference/HyperSpec/Body/f_funcal.htm
From: Matthew Danish
Subject: Re: Newbie: Quick Question regarding Disassembling a list
Date: 
Message-ID: <20040430023141.GW25328@mapcar.org>
On Thu, Apr 29, 2004 at 06:59:48PM -0700, pkhuong wrote:
> "Eric Strudel" <··········@hotmail.com> wrote in message news:<···················@fe08.usenetserver.com>...
> > Hello,
> > 
> > If I have a list say (setq list1 '(T T T T NIL)), is there a way to
> > disassemble that list into individual atoms without using a loop so that I
> > can do a binary AND for them?
> > 
> > For example, (and (T T T T NIL)) gives me NIL, but how can I access the (and
> > list1) so it will give me NIL as well?  Thanks!
> 
> apply http://www.lispworks.com/reference/HyperSpec/Body/f_apply.htm
> or
> funcall http://www.lispworks.com/reference/HyperSpec/Body/f_funcal.htm

AND is a macro.  You cannot FUNCALL or APPLY it, that wouldn't make
sense.  There is a function named EVERY which does what he wants.
Alternatively, (loop for l in list1 always l).

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: Ari Johnson
Subject: Re: Newbie: Quick Question regarding Disassembling a list
Date: 
Message-ID: <Wkkkc.34253$Jy3.8450@fed1read03>
Matthew Danish wrote:
> On Thu, Apr 29, 2004 at 06:59:48PM -0700, pkhuong wrote:
> 
>>"Eric Strudel" <··········@hotmail.com> wrote in message news:<···················@fe08.usenetserver.com>...
>>
>>>Hello,
>>>
>>>If I have a list say (setq list1 '(T T T T NIL)), is there a way to
>>>disassemble that list into individual atoms without using a loop so that I
>>>can do a binary AND for them?
>>>
>>>For example, (and (T T T T NIL)) gives me NIL, but how can I access the (and
>>>list1) so it will give me NIL as well?  Thanks!
>>
>>apply http://www.lispworks.com/reference/HyperSpec/Body/f_apply.htm
>>or
>>funcall http://www.lispworks.com/reference/HyperSpec/Body/f_funcal.htm
> 
> 
> AND is a macro.  You cannot FUNCALL or APPLY it, that wouldn't make
> sense.  There is a function named EVERY which does what he wants.
> Alternatively, (loop for l in list1 always l).
> 

Could you macroexpand it?  (eval (macroexpand (cons 'and list1))) seems 
to work for me.
From: Matthew Danish
Subject: Re: Newbie: Quick Question regarding Disassembling a list
Date: 
Message-ID: <20040430042115.GX25328@mapcar.org>
On Thu, Apr 29, 2004 at 09:10:50PM -0700, Ari Johnson wrote:
> >AND is a macro.  You cannot FUNCALL or APPLY it, that wouldn't make
> >sense.  There is a function named EVERY which does what he wants.
> >Alternatively, (loop for l in list1 always l).
> 
> Could you macroexpand it?  (eval (macroexpand (cons 'and list1))) seems 
> to work for me.

I strongly discourage this sort of solution.  MACROEXPAND and especially
EVAL are very heavy machinery to invoke, and there is no need for it.
Essentially, you are creating an entire separate Lisp interpreter or
even compiler process.  Also, EVAL does not operate in the current
lexical environment (since it is basically running a fresh new program).

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: Barry Margolin
Subject: Re: Newbie: Quick Question regarding Disassembling a list
Date: 
Message-ID: <barmar-877194.00435730042004@comcast.ash.giganews.com>
In article <······················@mapcar.org>,
 Matthew Danish <·······@andrew.cmu.edu> wrote:

> On Thu, Apr 29, 2004 at 09:10:50PM -0700, Ari Johnson wrote:
> > >AND is a macro.  You cannot FUNCALL or APPLY it, that wouldn't make
> > >sense.  There is a function named EVERY which does what he wants.
> > >Alternatively, (loop for l in list1 always l).
> > 
> > Could you macroexpand it?  (eval (macroexpand (cons 'and list1))) seems 
> > to work for me.
> 
> I strongly discourage this sort of solution.  MACROEXPAND and especially
> EVAL are very heavy machinery to invoke, and there is no need for it.
> Essentially, you are creating an entire separate Lisp interpreter or
> even compiler process.  Also, EVAL does not operate in the current
> lexical environment (since it is basically running a fresh new program).

Furthermore, unless you know for sure that list1 only contains 
self-evaluating objects, the above code has a bug.  It should be:

(eval (cons 'and (mapcar '(lambda (x) `',x))))

to prevent the elements of list1 from being evaluated.

The MACROEXPAND is unnecessary -- EVAL will expand macros when necessary.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Barry Margolin
Subject: Re: Newbie: Quick Question regarding Disassembling a list
Date: 
Message-ID: <barmar-CAD5A5.00262530042004@comcast.ash.giganews.com>
In article <····················@fed1read03>,
 Ari Johnson <·····@hotmail.com> wrote:

> Matthew Danish wrote:
> > On Thu, Apr 29, 2004 at 06:59:48PM -0700, pkhuong wrote:
> > 
> >>"Eric Strudel" <··········@hotmail.com> wrote in message 
> >>news:<···················@fe08.usenetserver.com>...
> >>
> >>>Hello,
> >>>
> >>>If I have a list say (setq list1 '(T T T T NIL)), is there a way to
> >>>disassemble that list into individual atoms without using a loop so that I
> >>>can do a binary AND for them?
> >>>
> >>>For example, (and (T T T T NIL)) gives me NIL, but how can I access the 
> >>>(and
> >>>list1) so it will give me NIL as well?  Thanks!
> >>
> >>apply http://www.lispworks.com/reference/HyperSpec/Body/f_apply.htm
> >>or
> >>funcall http://www.lispworks.com/reference/HyperSpec/Body/f_funcal.htm
> > 
> > 
> > AND is a macro.  You cannot FUNCALL or APPLY it, that wouldn't make
> > sense.  There is a function named EVERY which does what he wants.
> > Alternatively, (loop for l in list1 always l).
> > 
> 
> Could you macroexpand it?  (eval (macroexpand (cons 'and list1))) seems 
> to work for me.

Yes, you could, but that's not really good style.  In general, if 
there's a way to do something in a straightforward way without EVAL, 
it's preferable.  EVAL is a very big hammer.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: pkhuong
Subject: Re: Newbie: Quick Question regarding Disassembling a list
Date: 
Message-ID: <51184814.0404301007.4ce7f0c6@posting.google.com>
Matthew Danish <·······@andrew.cmu.edu> wrote in message news:<······················@mapcar.org>...
> AND is a macro.  You cannot FUNCALL or APPLY it, that wouldn't make
> sense.  There is a function named EVERY which does what he wants.
> Alternatively, (loop for l in list1 always l).
Oh, right, it's lazy.

Thanks for reminding me :)
From: Edi Weitz
Subject: Re: Newbie: Quick Question regarding Disassembling a list
Date: 
Message-ID: <m37jvycsfm.fsf@bird.agharta.de>
On Thu, 29 Apr 2004 18:39:54 -0400, "Eric Strudel" <··········@hotmail.com> wrote:

> If I have a list say (setq list1 '(T T T T NIL)), is there a way to
> disassemble that list into individual atoms without using a loop so
> that I can do a binary AND for them?
>
> For example, (and (T T T T NIL)) gives me NIL,

You probably mean (AND T T T T NIL) here.

> but how can I access the (and list1) so it will give me NIL as well?

Use EVERY:

  * (every #'identity '(t t t))

  T
  * (every #'identity '(t t nil))

  NIL

Edi.
From: Eric Strudel
Subject: Re: Newbie: Quick Question regarding Disassembling a list
Date: 
Message-ID: <RRfkc.11344$8S2.4048@fe06.usenetserver.com>
That worked great, thanks!


"Edi Weitz" <···@agharta.de> wrote in message
···················@bird.agharta.de...
> On Thu, 29 Apr 2004 18:39:54 -0400, "Eric Strudel"
<··········@hotmail.com> wrote:
>
> > If I have a list say (setq list1 '(T T T T NIL)), is there a way to
> > disassemble that list into individual atoms without using a loop so
> > that I can do a binary AND for them?
> >
> > For example, (and (T T T T NIL)) gives me NIL,
>
> You probably mean (AND T T T T NIL) here.
>
> > but how can I access the (and list1) so it will give me NIL as well?
>
> Use EVERY:
>
>   * (every #'identity '(t t t))
>
>   T
>   * (every #'identity '(t t nil))
>
>   NIL
>
> Edi.