[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Quoted function in `define-key'
From: |
Narendra Joshi |
Subject: |
Re: Quoted function in `define-key' |
Date: |
Mon, 06 Feb 2017 00:39:18 +0530 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) |
Michael Heerdegen <michael_heerdegen@web.de> writes:
> (info "(elisp) Symbol Components")
How did you insert this link to info?
>
>
>> What does the byte compiler do with this information? I am just
>> curious about this.
>
> When you sharp quote a lambda expression, the compiler knows that this
> lambda list is supposed to be called as a function, and will byte
> compile it. The evaluator might turn it into a closure when lexical
> binding is used.
>
> In elisp, the `lambda' macro comes with implicit function quoting (see
> its definition), so you can just omit it.
>
> But OTOH, it's an error to `quote' lambdas like
>
> '(lambda () body...)
>
> because it will prevent byte compilation or closure creation and make
> Stefan angry.
:)
> Obviously for `function' quoted symbols there is not much to do, but the
> byte compiler can determine whether that function is defined/ will be
> defined at run time, so it can warn you about typos as an extra service.
>
> For example, you get a compiler warning when compiling
>
> (define-key my-map [key] #'make-frame-cmomand)
>
> but not for
>
> (define-key my-map [key] 'make-frame-cmomand)
>
>> If this is recommended, I would also start quoting my functions as
>> #'my-function.
>
> Yes, it's a good idea.
Thanks! This is very informative.
--
Narendra Joshi
Re: Quoted function in `define-key', Stefan Monnier, 2017/02/04