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: Tim Johnson
Subject: Re: Proper use of function form
Date: Sun, 26 Apr 2020 16:43:46 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1


On 4/26/20 4:05 PM, Michael Heerdegen wrote:
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.

Thanks Michael. I will leave will enough alone.

cheers

--
Tim
tj49.com




reply via email to

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