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 17:58:32 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1


On 4/26/20 4:48 PM, Noam Postavsky wrote:
On Sun, 26 Apr 2020 at 19:27, Tim Johnson <tim@akwebsoft.com> wrote:

(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)) ?
No, you would put the function in the `my-keypairs' initializer:

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

I usually don't bother sharp-quoting in lists of functions though.

Wow! I had been thinking of that myself, but not fully understanding how symbols are evaluated in descending layers in sexps, this is a great second opinion.

Thank you Noam.

... and keep 'em coming

--
Tim
tj49.com




reply via email to

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