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: Stefan Monnier
Subject: Re: Quoted function in `define-key'
Date: Sat, 04 Feb 2017 13:10:34 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

>>>>> "Narendra" == Narendra Joshi <address@hidden> writes:

> The following piece of code is confusing me. It is from `rinari-minor-mode'.

> (dolist (el (append (mapcar
>                      (lambda (el)
>                        (cons (concat "f" (second el))
>                              (read (format "'rinari-find-%S"
>                                            (first el)))))
>                      rinari-jump-schema)
>                     rinari-minor-mode-keybindings))
>   (eval `(define-key rinari-prefix-map ,(car el) ,(cdr el))))


> If I replace the last expression with:

> (define-key rinari-prefix-map (car el) (cdr el))

> why does it fail?

> (cdr el) is (quote function-name) which is exactly the same as
> 'function-name.

"Exactly the same"?  Well, clearly not, since it behaves differently:

    (eval (cdr el))         =>   (quote function-name)
    (eval 'function-name)   =>   function-name

A good first rule is that if you're using `eval` it means you're not really
doing it right:

    (dolist (el (append (mapcar
                         (lambda (el)
                           (cons (vconcat [?\f] (nth 1 el))
                                 (intern "rinari-find-%s" (nth 0 el))))
                         rinari-jump-schema)
                        rinari-minor-mode-keybindings))
      (define-key rinari-prefix-map (car el) (cdr el)))


-- Stefan




reply via email to

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