all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Checking if all values of a list are true
@ 2008-07-11 11:23 Nordlöw
  2008-07-11 11:33 ` Nordlöw
  2008-07-11 16:38 ` David Kastrup
  0 siblings, 2 replies; 6+ messages in thread
From: Nordlöw @ 2008-07-11 11:23 UTC (permalink / raw)
  To: help-gnu-emacs

How do I check if all values of a list are true?

This is my attempt:
(reduce 'and '(t t))

but I get the error: and (invalid-function and)

(functionp 'and)

gives true so why on earth doesn't this work?


Thanks in advance,
Nordlöw


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Checking if all values of a list are true
  2008-07-11 11:23 Checking if all values of a list are true Nordlöw
@ 2008-07-11 11:33 ` Nordlöw
  2008-07-11 11:37   ` Nordlöw
  2008-07-11 16:38 ` David Kastrup
  1 sibling, 1 reply; 6+ messages in thread
From: Nordlöw @ 2008-07-11 11:33 UTC (permalink / raw)
  To: help-gnu-emacs

On 11 Juli, 13:23, Nordlöw <per.nord...@gmail.com> wrote:
> How do I check if all values of a list are true?
>
> This is my attempt:
> (reduce 'and '(t t))
>
> but I get the error: and (invalid-function and)
>
> (functionp 'and)
>
> gives true so why on earth doesn't this work?
>
> Thanks in advance,
> Nordlöw

Is there an alternative pure emacs-lisp way (non common-lisp (cl)) of
doing this?

/Nordlöw


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Checking if all values of a list are true
  2008-07-11 11:33 ` Nordlöw
@ 2008-07-11 11:37   ` Nordlöw
  2008-07-11 11:51     ` Florian Beck
  2008-07-11 11:56     ` Joost Kremers
  0 siblings, 2 replies; 6+ messages in thread
From: Nordlöw @ 2008-07-11 11:37 UTC (permalink / raw)
  To: help-gnu-emacs

On 11 Juli, 13:33, Nordlöw <per.nord...@gmail.com> wrote:
> On 11 Juli, 13:23, Nordlöw <per.nord...@gmail.com> wrote:
>
> > How do I check if all values of a list are true?
>
> > This is my attempt:
> > (reduce 'and '(t t))
>
> > but I get the error: and (invalid-function and)
>
> > (functionp 'and)
>
> > gives true so why on earth doesn't this work?
>
> > Thanks in advance,
> > Nordlöw
>
> Is there an alternative pure emacs-lisp way (non common-lisp (cl)) of
> doing this?
>
> /Nordlöw

It would be even better if Emacs already had a function typically
named any-p(arg-list) that returned t if all values in arg-list are
non-nil.

/Nordlöw


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Checking if all values of a list are true
  2008-07-11 11:37   ` Nordlöw
@ 2008-07-11 11:51     ` Florian Beck
  2008-07-11 11:56     ` Joost Kremers
  1 sibling, 0 replies; 6+ messages in thread
From: Florian Beck @ 2008-07-11 11:51 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw <per.nordlow@gmail.com> writes:

> On 11 Juli, 13:33, Nordlöw <per.nord...@gmail.com> wrote:
>> On 11 Juli, 13:23, Nordlöw <per.nord...@gmail.com> wrote:
>>
>> > How do I check if all values of a list are true?
>>
>> > This is my attempt:
>> > (reduce 'and '(t t))
>>
>> > but I get the error: and (invalid-function and)
>>
>> > (functionp 'and)
>>
>> > gives true so why on earth doesn't this work?

Maybe because 'and is a special form, not a function.

Try (reduce #'(lambda (x y) (and x y)) '(t t t t t t t))

> It would be even better if Emacs already had a function typically
> named any-p(arg-list) that returned t if all values in arg-list are
> non-nil.

Something like

(defmacro every-p (list)
  (cons 'and (eval list)))

CL has 'every:

(every 'eval '(t t t))
-- 
Florian Beck


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Checking if all values of a list are true
  2008-07-11 11:37   ` Nordlöw
  2008-07-11 11:51     ` Florian Beck
@ 2008-07-11 11:56     ` Joost Kremers
  1 sibling, 0 replies; 6+ messages in thread
From: Joost Kremers @ 2008-07-11 11:56 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw wrote:
> It would be even better if Emacs already had a function typically
> named any-p(arg-list) that returned t if all values in arg-list are
> non-nil.

(defmacro all-true (lst)
  `(and ,@lst)

AND is not a function (or a macro) but a special form. in my emacs (GNU
Emacs 23.0.60.1), (functionp and) returns nil, not t. which is presumably
why functions such as reduce, funcall, mapcar etc. do not accept it as an
argument.


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Checking if all values of a list are true
  2008-07-11 11:23 Checking if all values of a list are true Nordlöw
  2008-07-11 11:33 ` Nordlöw
@ 2008-07-11 16:38 ` David Kastrup
  1 sibling, 0 replies; 6+ messages in thread
From: David Kastrup @ 2008-07-11 16:38 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw <per.nordlow@gmail.com> writes:

> How do I check if all values of a list are true?
>
> This is my attempt:
> (reduce 'and '(t t))
>
> but I get the error: and (invalid-function and)
>
> (functionp 'and)
>
> gives true so why on earth doesn't this work?

Special form.  Try

(not (memq nil '(t t)))

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-07-11 16:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-11 11:23 Checking if all values of a list are true Nordlöw
2008-07-11 11:33 ` Nordlöw
2008-07-11 11:37   ` Nordlöw
2008-07-11 11:51     ` Florian Beck
2008-07-11 11:56     ` Joost Kremers
2008-07-11 16:38 ` David Kastrup

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.