Basic Tips

I/O

Reference

Looping over 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. There is also run! if you really want a nil return value.

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.