Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in elisp's let, how do you reference a variable bound in the same let while binding another variable?

Tags:

emacs

elisp

(let ((a 1) (b (+ a 1)))
  (message a))

This throws the error

Debugger entered--Lisp error: (void-variable a)

What's the canonical way to do this?

like image 813
jshen Avatar asked Jul 22 '11 18:07

jshen


1 Answers

The canonical way is to use let* (also note that I added a %s format string to your message form):

(let* ((a 1) (b (+ a 1)))
  (message "%s" a))

The let* function allows you to reference other variables that have previously been defined.

like image 92
zev Avatar answered Oct 09 '22 22:10

zev