Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to evaluate parts of a quoted expression in Emacs Lisp

Tags:

emacs

elisp

Say I have a function that returns a quoted list like so:

(defun create-structure (n l)
  '(structure (name . n)(label . l)))

I'd like the function to return:

(create-structure foo bar)
-> '(structure (name . foo)(label . bar))

Instead I get as excpected:

-> '(structure (name . n)(label . l))
like image 525
Gerstmann Avatar asked Feb 19 '23 05:02

Gerstmann


1 Answers

There are at least two ways to achieve this, Using the backquote syntax or an explicit call to list.

(defun create-structure-1 (n l)
  `(structure (name . ,n) (label . ,l)))

(defun create-structure-2 (n l)
  (list 'structure (cons 'name n) (cons 'label l)))

The GNU Emacs Lisp Reference provides a good read on the subject: - http://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html#Backquote

like image 169
Daniel Landau Avatar answered Mar 29 '23 18:03

Daniel Landau