Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluating a variable whose name is stored in a string

Tags:

emacs

elisp

Consider a problem of evaluating a variable who's name is a string:

(defun string-dereference ()
  (interactive)
  (let ((myStr "rst-adjust"))
  ;; (describe-function 'myStr) => Symbol's function definition is void: myStr
  ;; (funcall (format "(describe-function '%s)" myStr) => Invalid function: "(describe-function 'rst-adjust)")
  )

While the following works

(describe-function 'rst-adjust)

How do I do that given rst-adjust is stored in a string?

Edit:

The answer is:

(describe-function (intern myStr))
like image 268
Adobe Avatar asked Apr 29 '26 15:04

Adobe


1 Answers

intern is the function you're looking for:

(let ((my-str "rst-adjust"))
  (intern my-str))
==> rst-adjust
like image 102
legoscia Avatar answered May 04 '26 08:05

legoscia