variablesemacselispbackquote

Unquote symbol in lambda expression?


In an anonymous function such as

(lambda () x)

how can I replace the symbol x with its value in the current scope?

The only thing I can think of is

(eval `(lambda () ,x))

but I wonder if there's another way.


Solution

  • Remove the eval. Just `(lambda () ,x).

    That returns the list (lambda () VAL-X), where VAL-X is the value of variable x. And a lambda list is interpreted by Emacs as a function.