문제

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