Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elisp: referencing previous variables inside let [duplicate]

I'd like to define two variables in let, one of which depends on the value of the other, like so:

(let ((a (func))
      (b (if (eq a 1) 2 3)))
  ...)    

Obviously this is not the right way to do this, emacs says a is void. What's the right way to do this?

like image 285
Ron Avatar asked Sep 17 '13 18:09

Ron


1 Answers

Yes, you need to use let* instead of let.

Essentially, let* is a shortcut for nested lets:

(let ((a 1))
  (let ((b (1+ a)))
    (let ((c (* 2 b)))
      ...)))

is equivalent to

(let* ((a 1)
       (b (1+ a))
       (c (* 2 b)))
  ...)
like image 99
sds Avatar answered Oct 10 '22 22:10

sds