January 2014
Intermediate to advanced
232 pages
5h 11m
English
When writing real-world applications we need the tools to organize our code into logical groups. In object-oriented languages it’s common to use classes and define methods as members of a class. In Clojure, we group our functions into namespaces instead. Let’s look at how a namespace is defined.
| | (ns myns) |
| | |
| | (defn print-message [message] |
| | (println "message:" message)) |
| | |
| | (defn say-hello [user] |
| | (print-message (str "hello " user)) |
Here we have a namespace called myns containing two functions, print-message and say-hello. The functions in the same namespace can call each other directly. However, if we wanted to call these functions from a different namespace we would have to reference the myns first in the declaration ...
Read now
Unlock full access