Clojure for Java builders: What it’s essential to know

Learn extra at:

Code as information

Essentially the most outstanding factor you may discover when coming to Clojure from Java is that it’s homoiconic, which suggests the code is written within the type of the language’s information buildings. This follow, often known as code as information, leads to very constant syntax with a restricted variety of key phrases and constructs. It additionally creates a meta-programming mannequin utilizing “syntax-aware” code templates (referred to as macros).

The concept is that any snippet of Clojure code can be an occasion of Clojure information. You will notice this most ceaselessly within the listing syntax, as a result of most of Clojure is written as lists. Right here is an easy “Good day, InfoWorld” perform in Clojure:

(defn hello-infoworld [] 
  (println "Good day, InfoWorld"))

The parentheses point out a listing in Clojure. So, the definition of this perform is actually simply the definition of a listing with a key phrase (defn), a perform identify (hello-infoworld), an empty argument vector ([]), and the perform physique. The perform physique can be a listing containing a perform name (println) and the argument to that perform (“Good day, InfoWorld”).

Leave a reply

Please enter your comment!
Please enter your name here