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

[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: Sun, 05 Feb 2017 15:40:40 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Narendra Joshi <narendraj9@gmail.com> writes:
>
>>    (quote my-function) is exactly the same as 'my-function, i.e.
>
> Yes, the second is an alternative read syntax for the first expression.
>
>>    (eq (quote my-function) 'my-function) evaluates to t.
>>
>>    But here we are talking about the result of evaluating
>>
>>    (quote my-function) which isn't a cons but a symbol.
>
> No, it's a list (and a cons), but the result of evaluation is a symbol.
>
>>     But if we have `(quote my-function) that isn't the same as
>>    'my-function.
>
> `(quote my-function) and '(quote my-function) eval to the list
> (quote my-function).  ''my-function is an alternative read syntax for
> '(quote my-function).  But that all doesn't appear in the example.
>
> It's so: you want to specify a symbol as third argument to `define-key'.
> `define-key' is a function, so the argument positions are evaluated.
> Thus you want to specify an expression that evaluates to the symbol you
> want.  (quote my-function) or 'my-function evaluate to
> the symbol you want.  In
>
>    (define-key rinari-prefix-map (car el) (cdr el))
>
> the expression at that position is (cdr el), so that expression should
> eval to a symbol, not to a list like (quote symbol) - even when this
> list would give you what you want when it would be evaluated.
> Evaluation happens only once.
>
> With other words: when you write something like
>
>   (define-key my-map keys 'my-function)
This was really helpful. Thanks! :)

>
> you use the quote to prevent my-function from being evaluated, because
> you want to specify that symbol (unlike its binding as a variable), but
> _not_ because define-key would expect something quoted.
>
> BTW, most people prefer
>
>   (define-key my-map keys #'my-function)
> however.  #'my-function is a read syntax for (function my-function),
> where function is like quote but tells the byte compiler that the quoted
> thing is a function expression.

So, the symbol `my-function' can have the function definition in its
value slot? What does the byte compiler do with this information? I am
just curious about this. If this is recommended, I would also start
quoting my functions as #'my-function. 


>>    Side note: If anybody knows how to type inline code in gnus message,
>>    it would be greatly appreciated.
>
> I use `message-mark-inserted-region' for multiline code, but I don't
> know of any rule for smaller snippets.  Most of the time I don't care
> too much (like here).  It's good style to quote a `symbol' like this,
> but I sometimes avoid it when code snippets already involve lots of
> quoting.
Thanks! `message-mark-inserted-region' is good but I would probably change
the boundary that it inserts. :) 

-- 
Narendra Joshi



reply via email to

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