Skip to content
AgileLogics
4 min read

Comments and Style

Prerequisites: Functions

Comments

;; A comment on its own line uses two semicolons
(def tax-rate 0.2) ; after code, one semicolon

(defn with-tax
  "Returns price including tax.
  Docstrings appear in (doc with-tax) and in editors."
  [price]
  (* price (+ 1 tax-rate)))

#_(println "this form is skipped by the reader")

(comment
  (with-tax 100)
  ;; experiments for the REPL live here
  )

(println (with-tax 100))
120.0
  • ; starts a comment; by convention ;; for full-line comments and ; at the end of a line.
  • A docstring documents a function; it's available at runtime.
  • #_ makes the reader ignore the next form — great for temporarily disabling code.
  • (comment ...) holds REPL experiments (a "rich comment").

Style

The community Clojure Style Guide (guide.clojure.style) is the common reference. The essentials:

  • Indent with two spaces for bodies; align arguments that span lines.
  • Put all closing parentheses together on the last line — never on lines of their own.
  • kebab-case names; ? for predicates (valid?), ! for functions with side effects (save!), -> for conversions (map->user).
  • Keep functions small and pure; push side effects to the edges.
  • Prefer -> / ->> pipelines over deep nesting.
  • Use keywords for map keys and data-oriented design over classes.

Tools

  • clj-kondo — a fast linter; catches unused bindings, wrong arity, and redefined vars.
  • cljfmt or zprint — automatic formatting (Calva formats with cljfmt as you type).
  • clojure-lsp — navigation, refactoring, and linting in any editor.

What's next

You now know the core of Clojure. Try the Beginner Projects, then continue to Level 2 — Intermediate, which starts with sequences and laziness.