سؤال

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