Clojure is a dynamic functional language, and is a dialect of Lisp with a priority of concurrency. It can run on top of the JVM (Java Virtual Machine), CLR (Common Language Runtime) and Javascript platforms like NodeJS through ClojureScript.
Its pioneer is Rich Hickey, and if you have not heard his talks, I recommend this one on "Simple made easy". You can learn about the current state of adoption of the language in this Infoworld article.
If you'd like to understand why Clojure is a good choice to learn, Uncle Bob can tell you. Tl;dr "I began to realize that this language was the easiest, most elegant, least imposing language I had ever used – and not by a small margin.".
If you'd like to understand why Clojure is a good choice to learn, Uncle Bob can tell you. Tl;dr "I began to realize that this language was the easiest, most elegant, least imposing language I had ever used – and not by a small margin.".
If you have never interacted with Lisp, Clojure can have a steep learning curve. The aim of this post is not to give a level of understanding of how Clojure operates. Rather, it exists to help people realise they can achieve a basic program very quickly even if they do not yet understand the inner workings.
Create & Share Hello World
1. Automate your project: brew install leiningen *What is Leiningen?2. Start a project: lein new app my-clojure-project
3. Go to the project folder: cd my-closure-project
4. Run the project: lein run
5. Create a Java executable: lein uberjar *What's a Java executable?
6. Find the executable file: "my-closure-project-0.1.0-SNAPSHOT-standalone" in "/target/uberjar"
Understand main parts
1. Main program file: "core.clj" in "/src/my-clojure-project" *What is core.clj?
2. Project identifier (namespace): "ns my-clojure-project.core" *What's a namespace?
3. Program entry point: "defn -main"
4. Action taken: "(println "Hello, World!")" *Why the brackets?
Interact with your program through a REPL
1. Start the REPL from command line: lein repl *What's a REPL?
2. Notice you're in the project namespace: "my-clojure-project.core"
3. Run the entry point: type (-main) and press enter
Bonus: Do stuff with the REPL without a project
1. Start the REPL again if you stopped it: lein repl
2. Type something to evaluate: (+ 1 3)
3. Press enter and observe the result: "6"
4. Type something to use a built in function: (first [1 5 7]) *What is "first"?
5. Press enter and observe the result: "1"
Comments
Post a Comment