Clojure · Lesson 1 · On the house

Hello Clojure

println, prefix calls, comments, and running a file or REPL. Lesson 1 is free — on the house.

Lessons · Clojure · Lesson 1 of 10 · On the house

Hello Clojure

println, prefix calls, comments, and running a file or REPL.

Illustration for Clojure
Lesson 1 is on the house.

Clojure is a Lisp on the JVM. Code is written as lists: (println "hello") calls println with one argument. The function always comes first inside the parentheses.

Arithmetic is prefix too: (+ 1 2 3) is 6, and (* 2 (+ 3 4)) is 14. Operators take any number of arguments, so (< 1 2 3) checks the whole chain.

Comments start with ;. (comment ...) wraps code you want to keep but not run, and #_ skips the next form.

Run a file with the Clojure CLI, clj -M hello.clj, or with Babashka, bb hello.clj, which starts in milliseconds. Type clj alone to get a REPL, where you evaluate one form at a time.

Misses: writing println("hi") with the function outside the parens, or using // comments.

hello

; hello.clj
(println "hello")
(println (+ 1 2 3))
(println (* 2 (+ 3 4)))
(println (< 1 2 3))
Match this when you type.

Quiz

How do you call println with "hi" in Clojure?

Quiz

What is (* 2 (+ 3 4))?

Quiz

Which character starts a comment?

Quiz

What does (< 1 2 3) return?

Check

Match the still for: Hello Clojure.

Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.