From: Hubert =?ISO-8859-2?Q?Czobodzi=F1ski?=
Subject: conjunction of list elements
Date:
Message-ID: <d485pr$fhp$3@news.onet.pl>
Hi,
I am quite newbie and I have to calculate conjunction (and alternative) of
all elements of list. Following seems to work:
(eval (cons 'and '(t t nil)))
but I'm not sure if it is "politically correct"... Any better methods?
Hubert
You might look at the Lisp functions EVERY and SOME.
> (every 'identity '(t t t)) => T
> (every 'identity '(t nil t)) => NIL
> (some 'identity '(t nil t)) => T
Will Fitzgerald
Hubert Czobodzin'ski wrote:
> Hi,
>
> I am quite newbie and I have to calculate conjunction (and alternative) of
> all elements of list. Following seems to work:
> (eval (cons 'and '(t t nil)))
> but I'm not sure if it is "politically correct"... Any better methods?
(every 'identity <list>)
(some 'identity <list>)
Paul
From: ·········@cern.ch
Subject: Re: conjunction of list elements
Date:
Message-ID: <yzo4qe0cnnb.fsf@cern.ch>
(every #'identity (list t t nil))
EVAL you can pretty much forget about, at least for the coming 2-3
years:-)
Ole
·········@cern.ch writes:
> (every #'identity (list t t nil))
...which should make the OP reconsider how he came up with this
truth value list anyway!
> EVAL you can pretty much forget about, at least for the coming 2-3
> years:-)
Hmm? What happens in 2008?
--
(espen)
+ Espen Vestre <·····@vestre.net>:
| ·········@cern.ch writes:
|
| > EVAL you can pretty much forget about, at least for the coming 2-3
| > years:-)
|
| Hmm? What happens in 2008?
My guess: The OP has learned enough to know when to use eval.
Not to mention when not to use it, which is just about always.
--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
than thinking does: but it deprives us of whatever chance there is
of getting closer to the truth. -- C.P. Snow
Harald Hanche-Olsen <······@math.ntnu.no> writes:
> | Hmm? What happens in 2008?
>
> My guess: The OP has learned enough to know when to use eval.
> Not to mention when not to use it, which is just about always.
Ah. Of course.
--
(espen)
From: Hubert =?ISO-8859-2?Q?Czobodzi=F1ski?=
Subject: Re: conjunction of list elements
Date:
Message-ID: <d489gv$k7i$1@news.onet.pl>
>> (every #'identity (list t t nil))
>
> ...which should make the OP reconsider how he came up with this
> truth value list anyway!
habet, hoc habet!
thanks,
h.
From: ·········@cern.ch
Subject: Re: conjunction of list elements
Date:
Message-ID: <yzor7h4b6bl.fsf@cern.ch>
>> EVAL you can pretty much forget about, at least for the coming 2-3
>> years:-)
Espen> Hmm? What happens in 2008?
In 2008, Easter Sunday will be on March 23, and I'm allowing for the
possibility that the OP could come across some legitimate need for
EVAL sometime between that and the next time Easter falls on a still
earlier date.
Ole
Besides the great suggestion of using some or every, you
can also use member:
(defun conjunction (list)
(not (member nil list)))
CL-USER 8 > (conjunction '(t t nil))
NIL
CL-USER 9 > (conjunction '(t t t))
T
CL-USER 10 >
Wade
From: Hubert =?ISO-8859-2?Q?Czobodzi=F1ski?=
Subject: Re: conjunction of list elements
Date:
Message-ID: <d48kjq$77s$1@news.onet.pl>
> Besides the great suggestion of using some or every, you
> can also use member:
>
> (defun conjunction (list)
> (not (member nil list)))
I asked rather how to 'apply' operator 'and' to whole list at once. Finally
I found out that idea of building such list was stupid.
BTW, variety of methods to accomplish one task in Lisp is little
confusing...
h.
On Thu, 21 Apr 2005 18:38:46 +0200, <···@poczta.rachu.onet.ciachu.pl> wrote:
>
> BTW, variety of methods to accomplish one task in Lisp is little
> confusing...
Better not consider perl then, TIMTOWTDI.
--
Everyman has three hearts;
one to show the world, one to show friends, and one only he knows.
Hubert Czobodzinski wrote:
>>Besides the great suggestion of using some or every, you
>>can also use member:
>>
>>(defun conjunction (list)
>> (not (member nil list)))
>
>
> I asked rather how to 'apply' operator 'and' to whole list at once. Finally
> I found out that idea of building such list was stupid.
>
I know that, but as you know one cannot APPLY AND.
> BTW, variety of methods to accomplish one task in Lisp is little
> confusing...
>
Well, there is nothing wrong with being confused.
They may look like like different methods, but at their heart they are
the same. (Once you understand the "principle" of what is going
on).
Wade
Hubert Czobodzin'ski wrote:
>>Besides the great suggestion of using some or every, you
>>can also use member:
>>
>>(defun conjunction (list)
>> (not (member nil list)))
>
>
> I asked rather how to 'apply' operator 'and' to whole list at once. Finally
> I found out that idea of building such list was stupid.
>
> BTW, variety of methods to accomplish one task in Lisp is little
> confusing...
<g> as you get more familiar with the variety of methods you will stop
seeing them as interchangeable, if only because one makes for more
readable code (not that that is a minor consideration).
kenny
--
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film
"Doctor, I wrestled with reality for forty years, and I am happy to
state that I finally won out over it." -- Elwood P. Dowd