Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between def and defonce in Clojure?

Tags:

What is the difference between def and defonce in Clojure?

When to use def over defonce or vice versa?

like image 543
Ertuğrul Çetin Avatar asked May 20 '16 12:05

Ertuğrul Çetin


1 Answers

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 
like image 76
mishadoff Avatar answered Sep 20 '22 08:09

mishadoff