open:var

var

  • defn : var에 함수 할당
  • defmacro : var에 매크로 할당
  • defonce : 바인딩되지 않은 var에 값을 할당
  • defmulti : var에 멀티메서드 할당

명명된 var는 다른 참조 타입들과는 달리 그 이름으로 평가하면 자동적으로 역참조가 수행되어 #'가 앞에 붙게 된다
@deref를 직접 호출하지 않아도 된다

(def favorite-color :green)
#'user/favorite-color

favorite-color
;=> :green

그래서 값이 아닌 바인딩된 var를 참조하려면 #' 또는 동일한 의미의 특수 구문 var를 사용해야 한다

(var favorite-color)
;=> #'user/favorite-color

초기화 방법 (resolve 'x) (bound? #'x) (thread-bound? #'x)
(def x) #'user/x false false
(def x 5) #'user/x true false
(binding [x 7] …) #'user/x true true
(with-local-vars [x 9] …) nil true true

  • open/var.txt
  • 마지막으로 수정됨: 2021/11/06 11:18
  • 저자 127.0.0.1