From: rk
Subject: using and with apply
Date: 
Message-ID: <1176241389.042790.273740@y5g2000hsa.googlegroups.com>
Hi,

I am a newbie to the group and trying to pick-up the lisp skills. Need
to understand why I can't get and function to work with apply as
follows:

(apply 'and '(nil t nil))  -> invalid function: #<subr and>
(and nil t nil) -> nil  : as expected

I was under the impression that apply can figure out how to apply the
function on the list.  I am using Emacs lisp.

Any help is appreciated.

thanks/regards
--rk

From: Matthias Benkard
Subject: Re: using and with apply
Date: 
Message-ID: <1176242201.725315.5800@n59g2000hsh.googlegroups.com>
Hi,

> I was under the impression that apply can figure out how to apply the
> function on the list.

AND is not a function, it's a macro.  That's one of the disadvantages
of macros: You can't APPLY them.

> I am using Emacs lisp.

It's the same in Emacs-Lisp as in Common Lisp (at least I think so).
Do note, though, that comp.lang.lisp is usually the wrong group to ask
for Emacs-Lisp-specific advice.  The newsgroup about Emacs, whatever
it's called, is a better place to ask those kinds of questions.

Anyway, if you want to know more about this specific problem, you
should read about macros in your tutorial of choice.

For Common Lisp, you can look here:
http://www.gigamonkeys.com/book/macros-standard-control-constructs.html

Or here: http://www.psg.com/~dlamkins/sl/chapter03-08.html

Or wherever...

For Emacs-Lisp, this is probably what you want:
http://www.gnu.org/software/emacs/elisp-manual/html_node/Macros.html#Macros

Bye-bye,
Matthias
From: Ari Johnson
Subject: Re: using and with apply
Date: 
Message-ID: <m2mz1fbuhm.fsf@hermes.theari.com>
"Matthias Benkard" <··········@gmail.com> writes:

> Hi,
>
>> I was under the impression that apply can figure out how to apply the
>> function on the list.
>
> AND is not a function, it's a macro.  That's one of the disadvantages
> of macros: You can't APPLY them.
>
>> I am using Emacs lisp.
>
> It's the same in Emacs-Lisp as in Common Lisp (at least I think so).
> Do note, though, that comp.lang.lisp is usually the wrong group to ask
> for Emacs-Lisp-specific advice.  The newsgroup about Emacs, whatever
> it's called, is a better place to ask those kinds of questions.
>
> Anyway, if you want to know more about this specific problem, you
> should read about macros in your tutorial of choice.
>
> For Common Lisp, you can look here:
> http://www.gigamonkeys.com/book/macros-standard-control-constructs.html
>
> Or here: http://www.psg.com/~dlamkins/sl/chapter03-08.html
>
> Or wherever...
>
> For Emacs-Lisp, this is probably what you want:
> http://www.gnu.org/software/emacs/elisp-manual/html_node/Macros.html#Macros

Additionally, anytime you run into this problem be sure to ask the
language whether there is an alternative designed into it to deal with
your situation.

(apply 'and list) is invalid, but you can use (every 'identity list)
to get the same result.
From: Thomas F. Burdick
Subject: Re: using and with apply
Date: 
Message-ID: <1176281642.387139.222330@d57g2000hsg.googlegroups.com>
On Apr 11, 2:55 am, Ari Johnson <·········@gmail.com> wrote:
> (apply 'and list) is invalid, but you can use (every 'identity list)
> to get the same result.

And, if you (require 'cl), there is an `every' function available in
elisp.

I'm ambivalent about elisp questions here: on the one hand, the emacs
groups are usually a better place to ask them, on the other hand if
you ask this question there, you might get an answer involving when
and throw.
From: rk
Subject: Re: using and with apply
Date: 
Message-ID: <1176329240.941326.85340@b75g2000hsg.googlegroups.com>
On Apr 10, 5:56 pm, "Matthias Benkard" <··········@gmail.com> wrote:
> Hi,
>
> > I was under the impression that apply can figure out how to apply the
> > function on the list.
>
> AND is not a function, it's a macro.  That's one of the disadvantages
> of macros: You can't APPLY them.
>
> > I am using Emacs lisp.
>
> It's the same in Emacs-Lisp as in Common Lisp (at least I think so).
> Do note, though, that comp.lang.lisp is usually the wrong group to ask
> for Emacs-Lisp-specific advice.  The newsgroup about Emacs, whatever
> it's called, is a better place to ask those kinds of questions.
>
> Anyway, if you want to know more about this specific problem, you
> should read about macros in your tutorial of choice.
>
> For Common Lisp, you can look here:http://www.gigamonkeys.com/book/macros-standard-control-constructs.html
>
> Or here:http://www.psg.com/~dlamkins/sl/chapter03-08.html
>
> Or wherever...
>
> For Emacs-Lisp, this is probably what you want:http://www.gnu.org/software/emacs/elisp-manual/html_node/Macros.html#...
>
> Bye-bye,
> Matthias

Folks,

Thanks a lot! I think it helps. I am trying to learn lisp and since I
have the emacs on my system, I started using the emacs-lisp. My
question was more on the lisp language than an implementation. But I
will try to take care of the posting in the right group.

My next question is purely related to lisp:  given a symbol, how do we
know if it is a macro or a function without looking at the
implementation?

thanks much in advance
--rk
From: Drew Crampsie
Subject: Re: using and with apply
Date: 
Message-ID: <461d552c$0$16315$88260bb3@free.teranews.com>
rk wrote:

> My next question is purely related to lisp:  given a symbol, how do we
> know if it is a macro or a function without looking at the
> implementation?

Try looking at the documentation. Usually much more readable than the
impementation, and a less noisy than asking comp.lang.lisp.

drewc
> 
> thanks much in advance
> --rk
> 

-- 
Posted via a free Usenet account from http://www.teranews.com
From: =?iso-8859-1?B?QXNiavhybiBCavhybnN0YWQ=?=
Subject: Re: using and with apply
Date: 
Message-ID: <1176348029.796785.59280@y80g2000hsf.googlegroups.com>
On Apr 12, 6:07 am, "rk" <········@gmail.com> wrote:

> My next question is purely related to lisp:  given a symbol, how do we
> know if it is a macro or a function without looking at the
> implementation?

macro-function takes a symbol, and returns the macro-expansion
function
if it exists, otherwise nil:

CL-USER 1 > (macro-function 'and)
#<Function AND 207D24A2>

CL-USER 2 > (macro-function 'identity)
NIL

(http://www.lispworks.com/documentation/HyperSpec/Body/
f_macro_.htm#macro-function)
--
 -asbjxrn