0

How can I make fun2 return as the same as fun1?

(defun fun1 ()
  '((hello . "test"))) ; <= returns ((hello . "test"))

(defun fun2 (str)
  '((hello . str))) ; <= this is wrong! should return ((hello . "test"))
2
(defun fun2 (str)
  `((hello . ,str)))

See the backquote section of the Emacs manual:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html

  • 2
    Or (defun fun2 (str) (list (cons 'hello str))). It doesn't hurt to look behind the "magic" of backquoting. – Drew Jan 10 '18 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.