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"))
Drew
  • 75,699
  • 9
  • 109
  • 225
e19293001
  • 207
  • 1
  • 9

1 Answers1

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

lawlist
  • 18,826
  • 5
  • 37
  • 118
  • 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 05:10