1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00

Add Define Something Only Once as a clojure til

This commit is contained in:
jbranchaud
2016-05-16 20:52:48 -05:00
parent c0ae3009bf
commit bb7ca94369
2 changed files with 24 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
# Define Something Only Once
Clojure provides [`defonce`](https://clojuredocs.org/clojure.core/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:
```clojure
(defonce stuff 5)
#'user/stuff
user=> (defonce stuff "what")
nil
user=> stuff
5
user=> (def stuff "okay")
#'user/stuff
user=> stuff
"okay"
```