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"))
(defun fun2 (str)
  `((hello . ,str)))

See the backquote section of the Emacs manual:


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