Вопрос

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?

Это было полезно?

Решение

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)))
  ...)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top