Ctrl+P again to print, arrows/tab to navigate results, enter to confirm

    Basic Tips

    I/O

    Reference

    Looping

    There are many of ways to loop in Clojure. Here's some advice on when to use what:

    Ironically, the loop macro is never optimal.

    Handling Arguments

    (mapv #(println %)*command-line-args*)
    (doseq[a *command-line-args*](println a))
    

    Usually mapv is best, but doseq is better when you have other nested short fns.

    Indexing

    There're a few different ways to get a value from a sequence:

    (ds idx)               ; Shortest, but only works for vectors, sets, and maps; no default and errors when out of range
    (ds idx default?)      ; Has default, but only works for maps
    (get ds idx default?)  ; Nil/default when out of range, but only for indexed sequences
    (nth ds idx)           ; Works for all sequences, even lazy ones
    

    Conditionals

    (if cond x y)          ; Short circuits, you can leave the false section out to return nil, needs a truthy or (falsey/nil) condition
    (and/or cond x)        ; Short circuits, multiple conditions
    (case n v x default)   ; Short circuits, checks specific values, has default
    ({v x}n default)       ; Same as case, but no short circuit
    ([x y]n)               ; Needs a numeric 0/1 condition
    (get[x y]n default)    ; 0/1 condition or non-short-circuiting default
    

    Syntax-quoting

    Syntax-quoting can be used instead of sequence fns in a variety of cases:

    (concat a b)
    ; vs
    `(~@a~@b)
    
    (cons a b)
    ; vs
    `(~a~@b)
    

    All sequences can be spliced inside syntax-quoting, including strings, sets, maps, and nil.

    Vector and set literals can also be used:

    (conj s a)
    ; vs
    `#{~@s~a}
    ; vs
    `[~@s~a]
    

    Map literals work too, but require an even number of forms inside.