Last active
April 22, 2020 10:32
-
-
Save joshkh/69de5cb0d5f4fe936612bbee6b00eb4c to your computer and use it in GitHub Desktop.
Clojure Indentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn some-generic-function | |
"Demonstrate Clojure indentation and styles. | |
This doc string spans multiple lines, and the beginning of each line | |
is inline with the opening quotation mark" | |
[] | |
; ns :require values are aligned | |
; ns :import values are aligned | |
; but :require values do not align with :import values | |
(ns project.namespace | |
(:require [project-one.library] | |
[project-two.library]) | |
(:import (java.util UUID) | |
(java.io Bits | |
StringBuffer | |
ByteArrayInputStream))) | |
; new lines in s-expression are indented by two spaces | |
'indented-by-two-spaces | |
; same-line comments are prepended with one space | |
:some-keyword ; and a comment here | |
; rest of arguments are aligned with first argument | |
(some-function :arg-a | |
:arg-b | |
:arg-c) | |
; 1 space indent on list forms | |
[:a | |
:b | |
:c] | |
; map values are aligned | |
{:first-value 12345 | |
:second-value 67 | |
:and-the-third-value 890} | |
; let values are aligned | |
(let [the-first-result "first result" | |
another "second result"]) | |
; case values align with case | |
(case :b | |
:is-b :b | |
:is-not-b (not :b)) | |
; thread first macro arguments are aligned | |
(-> :value-one | |
:function-one | |
:function-two) | |
; thread second marco arguments are aligned | |
(->> :value-one | |
:function-one | |
:function-two) | |
; cond values are not aligned with function | |
(cond | |
(true? false) :a | |
(some? (not-empty [] :b)) | |
:else nil)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment