#elisp let, let* 로컬 바인딩이 언제 이루어지는가

less than 1 minute read

(when windows?
  (let ((git-dir "C:/Program Files/Git")
        (bash-dir "C:/Program Files/Git/bin"))
    ;;...
    ))

’C:/Program Files/Git’ 문자열 중복이 있다. let form으로 로컬 변수(local variable)를 만들 때, 이전에 만든 로컬 변수를 사용 못 해서 이렇게 중복을 놔뒀다.

(when windows?
  (let* ((git-dir "C:/Program Files/Git")
         (bash-dir (concat (file-name-as-directory git-dir) "bin")))
    ;;...
    ))

let* form을 사용하면 중복을 없앨 수 있다.

Special Form: let* (bindings…) forms…

This special form is like let, but it binds each variable right after computing its local value, before computing the local value for the next variable. Therefore, an expression in bindings can refer to the preceding symbols bound in this let* form.

로컬 변수는 심볼(symbol)에 값을 로컬 바인딩(local binding)해서 만들어진다. 로컬 바인딩이 이루어지는 시점이 다르다. let* form은 바로 만들어진다.

참고

C-x C-s C-x C-c