forked from vedang/csaoid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclojure
124 lines (88 loc) · 3.07 KB
/
clojure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
Clojure Cheat Sheet
==================
* Documentation
doc find-doc source (clojure.contrib.repl-utils)
* Data Structures
** Numbers
Computation : + - * / inc dec quot rem min max rationalize
Comparison : == < > <= >= zero? pos? neg?
Bitwise ops : bit-{and, or, xor, not, flip, set, shift-right,
: shift-left, and-not, clear, test}
Integer ops : odd even
Random num : rand rand-int
BigInt ops : with-precision
Unchecked : unchecked-{add, dec, divide, inc, multiply, negate,
: remainder, subtract}
** Strings
str, string?, pr-str, prn-str, print-str, println-str, with-out-str
** Characters
char, char-name-string, char-escape-string
** Lists
Create : () list list*
List as stack : peek, pop
Examine : list?
** Vectors
Create : [] vector vec
Examine : get nth peek rseq vector?
'Change' : assoc pop subvec replace
** Maps
Create : {} hash-map sorted-map sorted-map-by
'Change' : assoc dissoc select-keys merge merge-with zipmap
Examine : get contains? find keys vals map?
Entry : key val
** StructMaps
Setup : create-struct defstruct accessor
Individual : struct-map struct
** ArrayMaps
Create : array-map
** Sets
Create : #{} hash-set sorted-set set get conj disj contains? count
: seq
Operations : union difference intersection
Rel. Algebra : select index rename join project map-invert rename-keys
** Misc
Collections : count conj seq
Keywords : keyword keyword?
Symbols : symbol symbol? gensyms
* Sequences
** Seq in, Seq out
Get shorter seq : distinct filter remove for
Get longer seq : cons concat lazy-cat mapcat cycle interleave
: interpose
Head-items missing : rest frest rrest drop drop-while nthrest for
Tail-items missing : take take-nth take-while butlast drop-last for
Rearrangement : reverse sort sort-by
Nested Seqs : split-at split-with partition
Process each item : map pmap mapcat for replace seque
** Using a seq
Extract item : first ffirst rfirst second nth when-first last
Construct a coll : zipmap into reduce set vec into-array to-array-2d
Pass items to fn : apply
Get a boolean : empty? not-empty some not-any? every? not-every?
: reduce seq? counted? sorted? contains? reversible?
: sequential? associative?
Search a seq : some filter
Force evaluation : doseq dorun doall
** Creating a lazy seq
From collection : seq vals keys rseq subseq rsubseq
From producer fn : lazy-seq repeatedly iterate
From constant : repeat replicate range
From other objects : line-seq resultset-seq re-seq tree-seq file-seq
: xml-seq iterator-seq enumeration-seq
* Reader macros
' : Quote 'form -> (quote form)
\ : Character literal
; : Single line comment
^ : Meta ^form -> (meta form)
@ : Deref @form -> (deref form)
` : Syntax quote
~ : Unquote
~@ : Unquote-splicing
#"p" : Regex pattern p
#^ : Meta data
#' : Var quote #'x -> (var x)
#() : #(...) -> (fn [args] (...))
* Special forms
def if do let quote var fn loop recur throw try monitor-enter monitor-exit
* Misc Idiomatic stuff
Check if Seq contains a value: (some #{value} seq)