Alice: reference to previous variables inside let

I would like to define two variables in let, one of which depends on the value of the other, for example:

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

Obviously this is the wrong way to do this, emacs says a not valid. What is the right way to do this?

+4
source share
1 answer

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

Essentially, let* is a shortcut for nested let s:

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

equivalently

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

Source: https://habr.com/ru/post/1502666/


All Articles