1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 23:28:02 +00:00
Files
til/clojure/define-something-only-once.md
2016-05-16 20:53:02 -05:00

520 B

Define Something Only Once

Clojure provides defonce which is a macro that defines something only once. Once a variable has been bound to a value, subsequent attempts to do defounce for that variable will go unevaluated. This will have no implications for how the def special form works.

Here is an example:

(defonce stuff 5)
#'user/stuff
user=> (defonce stuff "what")
nil
user=> stuff
5
user=> (def stuff "okay")
#'user/stuff
user=> stuff
"okay"