help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper use of function form


From: Michael Heerdegen
Subject: Re: Proper use of function form
Date: Mon, 27 Apr 2020 02:05:29 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Tim Johnson <tim@akwebsoft.com> writes:

> Would it be better to change (nth (+ ndx 1) mylist) to
> (function (nth > (+ ndx 1) mylist)) ?

No:

"Like `quote', but preferred for objects which are functions.
In byte compilation, `function' causes its argument to be handled by
the byte compiler.  `quote' cannot do that."

"(nth > (+ ndx 1) mylist)" is not a function - it is an
expression that will evaluate to a function.  Since `function' acts like
`quote', using this special form would prevent that evaluation, so it
won't work.

The underlying problem is that your expression is evaluated at
run-time.  Useful for the compiler would only be a function name known
at compile time.  If you know the function name at compile time, you
don't want to eval it at run time, so you want to `quote' anyway.

So what can you do?  Since we don't have a multiple-define-key function,
you can just stay with your loop as is - there is nothing wrong with
that, but you'll not get compiler warnings like "unknown function".  You
can also use a macro that would expand to a sequence of `define-key'
calls at compile time.  Or construct the whole keymap at compile time,
using list functions (or `backquote').  But that's rather uncommon.
Most people just write the key definition calls out or just don't care -
even in the Emacs sources.


Michael.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]