List comparison misses elements in Clojure
There are a few omissions from Clojure. Also there are several uses of Java interop to get effect that are built into the standard Clojure system. Included are suggested improvements.
Identifier characters can contain non-alphnumeric unicode (though for a standard keyboard the description is correct).
If binary predicates can be considered, then "type predicates" should include "instance?"
Relational operators should read "= not= < > <= >="
Rational decomposition should be "numerator denominator"
Random number should be (rand) (rand 100), (rand-int 100)
Character access can be (nth "foo" 0)
Extract substring: (subs "foo bar" 4 7) and (subs "foo bar" 4)
Length can be: (count "foo")
Constructors: (apply str (repeat 3 \f)) (apply str '(\f \o \o))
Comparison: (= "foo" "bar") (compare "foo" "bar")
Case: (clojure.string/lower-case "FOO")
Trim: (clojure.string/trim " foo ")
Split: (split "foo bar baz" #"[ \t\n]+")
Join: (apply str '("foo" "bar" "baz"))
Format: (format "%s: %d %.2f" "Foo" 7 13.457)
Regex substitution: (clojure.string/replace "hello" #"[^l]l" "XX") (clojure.string/replace-all "hello hello" #"[^l]l" "XX"
Current date/time: (java.util.Date.)
Sequence predicate: (seq? '(1 2 3)) (sequential? '(1 2 3)) (sequential? [1 2 3]) (vector? [1 2 3])
Iterate over hash entries: (doseq [[k v] h](println k) (println v)). Alternatively, use "key" and "val" instead of "first" and "second"
Map hash to list: (def hkeys (keys h)) (def hvals (vals h))
Defstruct: (deftype account [id balance])
Struct: (def a (->acc 3 17.12))
Struct setter: (assoc a :balance 0)
Struct predicate: (record? a)
Variable number of arguments: (defn add [a & b](if %28nil? b%29 a %28apply + a b%29))
Named parameter: (defn logarithm [&{x :number b :base}](/ %28Math/log x%29 %28Math/log b%29)) (logarithm :base 2 :number 8)
Return multiple values is always done with a vector: (defn sqrts [x] [(Math/sqrt x) (- (Math/sqrt x)])
Create thread: (future (println "running..."))
Wait on a thread: (def t (future (Thread/sleep (* 30 1000)))) (deref t)
Read line from stdin: (def line (read-line))
Open file for reading: (def in (clojure.java.io/reader "/etc/hosts"))
Open file for writing: (def out (clojure.java.io/writer "/tmp/test"))
Open file for appending: (def out (clojure.java.io/writer "/tmp/test" :append true))
Close file implicitly: (with-open [out (clojure.java.io/writer "/tmp/test")](.write out))
Read file into array of strings: (clojure.string/split-lines (slurp "/etc/hosts"))
Read file into string: (slurp "/etc/hosts")
Write string: (spit "/tmp/test" "lorem ipsum")
Write line: (do (.write out "lorem ipsum") (.newLine out))
Flush file handle: (.flush out)
File test, regular file test: (.exists (clojure.java.io/file "/tmp/foo")) (.isFile (clojure.java.io/file "/tmp/foo"))
File size: (.length (clojure.java.io/file "/tmp/foo"))
Is file readable, writable, executable: (def f (clojure.java.io/file "/tmp/foo")) (.canRead f) (.canWrite f) (.canExecute f)
Set file permissions: (def f (clojure.java.io/file "/tmp/foo")) (.setReadable f true) (.setWritable f true) (.setExecutable f true)
Copy file, remove file, rename file: (clojure.java.io/copy "/tmp/foo" "/tmp/bar") (clojure.java.io/delete (clojure.java.io/file "/tmp/foo")) (.renameTo (clojure.java.io/file "/tmp/foo") (clojure.java.io/file "/tmp/bar"))
Create temp file: (java.io.File/createTempFile "foo" ".tmp")
There is some inconsistency between accepting new values vs. mutation. For instance, "push" suggests that Clojure has no equivalent (it can use conj, but this creates a new sequence), while "set element vector" and "rem-hash" suggest "replace" and "dissoc", which will not change the value of the provided vector.