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
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
"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.
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.
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
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
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