aboutsummaryrefslogtreecommitdiff
path: root/def.clj
diff options
context:
space:
mode:
Diffstat (limited to 'def.clj')
-rw-r--r--def.clj7
1 files changed, 7 insertions, 0 deletions
diff --git a/def.clj b/def.clj
index a198795b..367d1fda 100644
--- a/def.clj
+++ b/def.clj
@@ -17,6 +17,13 @@
(clojure/in-ns 'def)
(clojure/refer 'clojure)
+(defmacro init-once
+ "Initializes a var exactly once. The var must already exist."
+ [var init]
+ `(let [v# (resolve '~var)]
+ (when-not (.isBound v#)
+ (.bindRoot v# ~init))))
+
(defmacro defvar
"Defines a var with an optional intializer and doc string"
([name]