HomeCloud ComputingClojure for Java builders: What it's essential know

Clojure for Java builders: What it’s essential know



Code as information

Probably the most exceptional 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, also called 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 thought is that any snippet of Clojure code can be an occasion of Clojure information. You will note this most continuously within the listing syntax, as a result of most of Clojure is written as lists. Right here is an easy “Hey, InfoWorld” perform in Clojure:

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

The parentheses point out a listing in Clojure. So, the definition of this perform is basically 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 (“Hey, InfoWorld”).

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments