16
(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?

jshen
  • 11,507
  • 7
  • 37
  • 59

1 Answers1

30

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.

cjm
  • 61,471
  • 9
  • 126
  • 175
zev
  • 3,480
  • 18
  • 13