unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Narendra Joshi <narendraj9@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Quoted function in `define-key'
Date: Sat, 04 Feb 2017 18:25:40 +0100	[thread overview]
Message-ID: <87zii1dg17.fsf@drachen> (raw)
In-Reply-To: <87efzedmlk.fsf@vicarie.i-did-not-set--mail-host-address--so-tickle-me> (Narendra Joshi's message of "Sat, 04 Feb 2017 20:33:51 +0530")

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)

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.

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


HTH,

Michael.



  reply	other threads:[~2017-02-04 17:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-04 10:20 Quoted function in `define-key' Narendra Joshi
2017-02-04 11:11 ` Narendra Joshi
2017-02-04 12:05 ` Michael Heerdegen
2017-02-04 15:03   ` Narendra Joshi
2017-02-04 17:25     ` Michael Heerdegen [this message]
2017-02-05 10:10       ` Narendra Joshi
2017-02-05 13:50         ` Michael Heerdegen
2017-02-05 19:09           ` Narendra Joshi
2017-02-05 19:45             ` Michael Heerdegen
2017-02-04 18:10 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zii1dg17.fsf@drachen \
    --to=michael_heerdegen@web.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=narendraj9@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).