Apply Clojure style conventions to ensure code is clear, consistent, and maintainable
A concise summary of key Clojure style conventions for LLM context.
lisp-case for functions and variables: (def some-var), (defn some-fun)CapitalCase for protocols, records, structs, types: (defprotocol MyProtocol)?: (defn palindrome?)!: (defn reset!)-> for conversion functions: (defn f->c)*earmuffs* for dynamic vars: (def ^:dynamic *db*)_ for unused bindings: (fn [_ b] b):require over :use[clojure.string :as str][clojure.java.io :as io][clojure.edn :as edn][clojure.walk :as walk][clojure.zip :as zip][clojure.data.json :as json];; Good function style examples
(defn foo
"Docstring goes here."
[x]
(bar x))
;; Multiple arity - align args
(defn foo
"I have two arities."
([x]
(foo x 1))
([x y]
(+ x y)))
;; Threading macros for readability
(-> person
:address
:city
str/upper-case)
(->> items
(filter active?)
(map :name)
(into []))
[] over lists () for sequences{:name "John" :age 42}(filter #{:a :b} coll)vec over into [];; Use when instead of (if x (do ...))
(when test
(do-this)
(do-that))
;; Use if-let for conditional binding
(if-let [val (may-return-nil)]
(do-something val)
(handle-nil-case))
;; Use cond with :else
(cond
(neg? n) "negative"
(pos? n) "positive"
:else "zero")
;; Use case for constants
(case day
:mon "Monday"
:tue "Tuesday"
"unknown")
clojure.core/str[[var-name]]test/ directory *.test-test suffixdeftest macro;; Version added
(def ^{:added "1.0"} foo 42)
;; Deprecation
(def ^{:deprecated "2.0"} old-foo 42)
;; No documentation
(def ^:no-doc internal-thing 42)
;; Private
(def ^:private secret 42)
Add this context to your project via the
ctxs command line integration: