unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Proper use of function form
@ 2020-04-26 23:27 Tim Johnson
  2020-04-27  0:05 ` Michael Heerdegen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tim Johnson @ 2020-04-26 23:27 UTC (permalink / raw)
  To: MLEmacs

Here is a key definition:

(define-key jinja2-mode-map (kbd "C-c i") #'jinja2-insert-var)

As I understand it, the sharp-quote (#') tells the compiler that 
jinja2-insert-var is meant to be a function

The following quotation:

"it is always good practice to sharp quote every symbol that is the name 
of a function, whether it's going into a |mapcar|, an |apply|, a 
|funcall|, or anything else."

Can be found at 
https://endlessparentheses.com/get-in-the-habit-of-using-sharp-quote.html

fuurther text there describes the special 'function form for which the 
sharp-quote is a shorthand.

Suppose we are processing a sexp of alternating strings and symbols:

(setq my-keypairs '("h" my-h-func "g" my-g-func "f" my-f-func))

and using iteration to *programmatically* call define-key for multiple 
key definitions as in

(define-key mymap                               ;; add to keymap
     (kbd (concat ldr (nth ndx mylist)))    ;; sequence as in "g"
     (nth (+ ndx 1) mylist))                      ;; command as in my-g-func

The form above is indeed a snippet from a defun that I have used for years

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

I note that help for 'function states a preference for using it with 
function objects, but says nothing about processing a list. Hence I am 
lobbying wiser heads than mine for opinions before I implement something 
that might cause subtle problems down the road.

Emacs is GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, X toolkit, Xaw 
scroll bars)
on ubuntu 16.04

Thanks

-- f
Tim
tj49.com



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-27 19:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-26 23:27 Proper use of function form Tim Johnson
2020-04-27  0:05 ` Michael Heerdegen
2020-04-27  0:43   ` Tim Johnson
2020-04-27  0:48 ` Noam Postavsky
2020-04-27  1:58   ` Tim Johnson
2020-04-27  8:06 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-04-27 19:12   ` Tim Johnson

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