What is the difference between def and defonce in Clojure?
When to use def over defonce or vice versa?
defonce
is skipped when variable is already defined.
user> (def a 1) ;;=> #'user/a user> a ;;=> 1 user> (def a 2) ;;=> #'user/a user> a ;;=> 2 user> (defonce b 1) ;;=> #'user/b user> b ;;=> 1 user> (defonce b 2) ;;=> nil user> b ;;=> 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With