forked from dsevilla/clojure-cheatsheets
/
core.clj
2078 lines (1922 loc) · 107 KB
/
core.clj
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(ns generator.core
(:require [clojure.string :as str])
(:require [clojure.set :as set])
(:require [clojure.java.javadoc])
(:require [clojure.java.io :as io])
(:require [clojure.data.avl])
(:require [clojure.tools.reader.edn])
(:require [clojure data pprint repl set string xml zip])
(:require [clojure.core.reducers])
(:require [grimoire.util :as g.u]))
;; Andy Fingerhut
;; andy_fingerhut@alum.wustl.edu
;; Feb 21, 2011
;; TBD: Fix the broken link for ->> in the generated PDF files.
;; TBD: For commands specified via strings rather than symbols, "@",
;; make a way to specify the desired target URL right in the
;; structure. Maybe Clojure metadata would be a good way to do this,
;; since I expect it to be fairly uncommon?
;; TBD: Make an option to use a local file:///... root directory for
;; the URLs in links, in case someone wants to have a local copy on a
;; machine that is not always connected to the Internet, similar to
;; how the CLHS Hyperspec can be locally used?
;; Documentation describing the structure of the value of
;; cheatsheat-structure:
;; At the top level, the structure must be:
;;
;; [:title "title string"
;; :page <page-desc>
;; :page <page-desc>
;; ... as many pages as you want here ...
;; ]
;; A <page-desc> looks like:
;;
;; [:column <box-desc1> <box-desc2> ... :column <box-desc7> <box-desc8> ...]
;;
;; There must be exactly two :column keywords, one at the beginning,
;; and the rest must be <box-descriptions>.
;; A <box-desc> looks like:
;;
;; [:box "box color"
;; :section "section name"
;; :subsection "subsection name"
;; :table <table-desc>
;; ... ]
;;
;; It must begin with :box "box color", but after that there can be as
;; many of the following things as you wish. They can be placed in
;; any order, i.e. there is no requirement that you have a :section
;; before a :subsection, or have either one at all. The only
;; difference between :section and :subsection is the size of the
;; heading created (e.g. <h2> vs. <h3> in HTML).
;;
;; :section "section name"
;; :subsection "subsection name"
;; :table <table-desc>
;; :cmds-one-line [vector of cmds]
;; A <table-desc> is a vector of <row-desc>s, where each <row-desc>
;; looks like:
;;
;; ["string" :cmds '[<cmd1> <cmd2> <cmd3> ...]]
;;
;; or:
;;
;; ["string" :str <str-spec>]
;;
;; You can optionally replace :cmds with :cmds-with-frenchspacing
;;
;; Each <cmd> or <str-spec> (and "string" at the beginning) can be any
;; one of:
;;
;; (a) a symbol, in which case it should have a link created to the
;; documentation URL.
;;
;; (b) a vector of the form [:common-prefix prefix-symbol- suffix1
;; suffix2 ...]. This will be shown in a form that looks similar to
;; "prefix-symbol-{suffix1, suffix2, ...}", where suffix1 will have a
;; link to the documentation for the symbol named
;; prefix-symbol-suffix1 (if there is any), and similarly for the
;; other suffixes. Note: This cannot be used in the "string" position
;; in the examples above, only in place of one or more of the commands
;; after :cmds, or in place of <str-spec>. This is useful for
;; economizing on space for names like unchecked-add, unchecked-dec,
;; etc.
;;
;; (c) a vector of the form [:common-suffix -suffix prefix1 prefix2
;; ...]. This is similar to :common-prefix above, except that it will
;; be shown similar to "{prefix1, prefix2, ...}-suffix", and the
;; symbols whose documentation will be linked to will be
;; prefix1-suffix, prefix2-suffix, etc.
;;
;; (d) a vector of the form [:common-prefix-suffix prefix- -suffix
;; middle1 middle2 ...]. Similar to :common-prefix and :common-suffix
;; above, except that it will be shown similar to "prefix-{middle1,
;; middle2, ...}-suffix", and the symbols whose documentation will be
;; linked to will be prefix-middle1-suffix, prefix-middle2-suffix,
;; etc.
;;
;; (e) a string, in which case it should simply be copied to the
;; output as is.
;;
;; (f) a 'conditional string', which is a Clojure map of the form
;; {:html "html-string", :latex "latex-string}. Only "html-string"
;; will be output if HTML output is being gnerated, and only
;; "latex-string" will be output if LaTeX output is being generated.
;; Note: The last <box-desc> in the last page can optionally be
;; replaced with a <footer-desc>, but only one, and only in that
;; place. TBD: This has not yet been implemented.
(def cheatsheet-structure
[:title {:latex "Clojure Cheat Sheet (Clojure 1.3 - 1.6, sheet v26)"
:html "Clojure Cheat Sheet (Clojure 1.3 - 1.6, sheet v26)"}
:page [:column
[:box "green"
:section "Documentation"
:table [["clojure.repl/"
:cmds '[clojure.repl/doc clojure.repl/find-doc
clojure.repl/apropos clojure.repl/dir
clojure.repl/source
clojure.repl/pst clojure.java.javadoc/javadoc
"(foo.bar/ is namespace for later syms)"]]]
]
[:box "blue"
:section "Primitives"
:subsection "Numbers"
:table [["Literals" :cmds '[{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html}{Long}:"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html\">Long</a>:"}
"7,"
"hex" "0xff,"
"oct" "017,"
"base 2" "2r1011,"
"base 36" "36rCRAZY"
"BigInt:"
"7N"
"Ratio:"
"-22/7"
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html}{Double}:"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html\">Double</a>:"}
"2.78"
"-1.2e-5"
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html}{BigDecimal}:"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html\">BigDecimal</a>:"}
"4.2M"
]]
["Arithmetic" :cmds '[+ - * / quot rem mod inc dec
max min +' -' *' inc' dec']]
["Compare" :cmds '[== < > <= >= compare]]
["Bitwise" :cmds '[[:common-prefix bit- and or xor not
flip set shift-right shift-left
and-not clear test]
"(1.6)" unsigned-bit-shift-right
"(see"
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html}{BigInteger}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html\">BigInteger</a>"}
" for integers larger than Long)"
]]
["Cast" :cmds '[byte short int long float double
bigdec bigint num rationalize biginteger]]
["Test" :cmds-with-frenchspacing '[zero? pos? neg?
even? odd?
number? rational?
integer? ratio?
decimal? float?]]
["Random" :cmds '[rand rand-int]]
["BigDecimal" :cmds '[with-precision]]
;; TBD: Why do these not exist in Clojure?
;; There are -int versions, but not long
;; versions. unchecked-divide
;; unchecked-remainder. Filed ticket CLJ-1545
;; to add them.
["Unchecked" :cmds '[*unchecked-math*
[:common-prefix
unchecked-
add dec inc multiply negate
subtract]]]]
:subsection "Strings"
:table [["Create" :cmds '[str format
{:latex "\\href{http://clojure.org/reader\\#The\\%20Reader--Reader\\%20forms}{\"a string\"} \\",
:html "<a href=\"http://clojure.org/reader#The%20Reader--Reader%20forms\">\"a string\"</a>"}
{:latex "\"escapes \\textbackslash b\\textbackslash f\\textbackslash n\\textbackslash t\\textbackslash r\\textbackslash \" octal \\textbackslash 377 hex \\textbackslash ucafe\"",
:html "\"escapes \\b\\f\\n\\t\\r\\\" octal \\377 hex \\ucafe\"",}
{:latex "\\textmd{\\textsf{See also IO/to string}}",
:html "See also IO/to string"}]]
["Use" :cmds '[count get subs compare
{:latex "\\textmd{\\textsf{(clojure.string/)}}",
:html "(clojure.string/)"}
clojure.string/join clojure.string/escape
clojure.string/split clojure.string/split-lines
clojure.string/replace
clojure.string/replace-first
clojure.string/reverse
"(1.5)" clojure.string/re-quote-replacement
{:latex "(\\href{http://docs.oracle.com/javase/7/docs/api/java/lang/String.html}{String})"
:html "(<a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/String.html\">java.lang.String</a>)"}
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/lang/String.html\\#indexOf\\%28java.lang.String\\%29}{.indexOf}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf%28java.lang.String%29\">.indexOf</a>"}
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/lang/String.html\\#lastIndexOf\\%28java.lang.String\\%29}{.lastIndexOf}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#lastIndexOf%28java.lang.String%29\">.lastIndexOf</a>"}
]]
[
;; "Regex"
{:latex "\\href{http://www.regular-expressions.info}{Regex}"
:html "<a href=\"http://www.regular-expressions.info\">Regex</a>"}
:cmds '[
;; {:latex "\\#\"pattern\"",
;; :html "#\"<var>pattern</var>\""}
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html}{\\#\"pattern\"}",
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html\">#\"<var>pattern</var>\"</a>"}
re-find re-seq re-matches
re-pattern re-matcher re-groups
{:latex "\\textmd{\\textsf{(clojure.string/)}}",
:html "(clojure.string/)"}
clojure.string/replace
clojure.string/replace-first
"(1.5)"
clojure.string/re-quote-replacement]]
["Letters" :cmds '[{:latex "\\textmd{\\textsf{(clojure.string/)}}",
:html "(clojure.string/)"}
clojure.string/capitalize
clojure.string/lower-case
clojure.string/upper-case]]
["Trim" :cmds '[{:latex "\\textmd{\\textsf{(clojure.string/)}}",
:html "(clojure.string/)"}
clojure.string/trim clojure.string/trim-newline
clojure.string/triml clojure.string/trimr]]
["Test" :cmds '[char char? string?
{:latex "\\textmd{\\textsf{(clojure.string/)}}",
:html "(clojure.string/)"}
clojure.string/blank?
{:latex "(\\href{http://docs.oracle.com/javase/7/docs/api/java/lang/String.html}{String})"
:html "(<a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/String.html\">java.lang.String</a>)"}
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/lang/String.html\\#startsWith\\%28java.lang.String\\%29}{.startsWith}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#startsWith%28java.lang.String%29\">.startsWith</a>"}
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/lang/String.html\\#endsWith\\%28java.lang.String\\%29}{.endsWith}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#endsWith%28java.lang.String%29\">.endsWith</a>"}
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/lang/String.html\\#contains\\%28java.lang.CharSequence\\%29}{.contains}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#contains%28java.lang.CharSequence%29\">.contains</a>"}
]]
]
:subsection "Other"
:table [["Characters" :cmds '[char char-name-string
char-escape-string
{:latex "\\href{http://clojure.org/reader\\#The\\%20Reader--Reader\\%20forms}{literals}:",
:html "<a href=\"http://clojure.org/reader#The%20Reader--Reader%20forms\">literals</a>:"}
{:latex "\\textbackslash a",
:html "\\a",}
{:latex "\\textbackslash newline",
:html "\\newline",}
"(more at link)"]]
["Keywords" :cmds '[keyword keyword? find-keyword
{:latex "\\href{http://clojure.org/reader\\#The\\%20Reader--Reader\\%20forms}{literals}:",
:html "<a href=\"http://clojure.org/reader#The%20Reader--Reader%20forms\">literals</a>:"}
":kw" ":my.ns/kw" "::in-cur-ns"]]
["Symbols" :cmds '[symbol symbol? gensym
{:latex "\\href{http://clojure.org/reader\\#The\\%20Reader--Reader\\%20forms}{literals}:",
:html "<a href=\"http://clojure.org/reader#The%20Reader--Reader%20forms\">literals</a>:"}
"my-sym" "my.ns/foo"]]
["Misc" :cmds '[{:latex "\\href{http://clojure.org/reader\\#The\\%20Reader--Reader\\%20forms}{literals}:",
:html "<a href=\"http://clojure.org/reader#The%20Reader--Reader%20forms\">literals</a>:"}
"true" "false" "nil"]]
]
]
[:box "yellow"
:section "Collections"
:subsection "Collections"
:table [["Generic ops" :cmds '[count empty not-empty into conj
{:latex "\\textmd{\\textsf{(clojure.walk/)}}",
:html "(clojure.walk/)"}
clojure.walk/walk
clojure.walk/prewalk
clojure.walk/prewalk-demo
clojure.walk/prewalk-replace
clojure.walk/postwalk
clojure.walk/postwalk-demo
clojure.walk/postwalk-replace
]]
["Content tests" :cmds '[distinct? empty?
every? not-every? some not-any?]]
["Capabilities" :cmds '[sequential? associative? sorted?
counted? reversible?]]
["Type tests" :cmds '[coll? list? vector? set? map?
seq? "(1.6)" record?]]]
:subsection {:latex "Lists (conj, pop, \\& peek at beginning)"
:html "Lists (conj, pop, & peek at beginning)"}
:table [["Create" :cmds '["()" list list*]]
["Examine" :cmds-with-frenchspacing '[first nth peek
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html\\#indexOf\\%28java.lang.Object\\%29}{.indexOf}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html#indexOf%28java.lang.Object%29\">.indexOf</a>"}
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html\\#lastIndexOf\\%28java.lang.Object\\%29}{.lastIndexOf}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html#lastIndexOf%28java.lang.Object%29\">.lastIndexOf</a>"}
]]
[{:html "'Change'", :latex "`Change'"}
:cmds '[cons conj rest pop]]
]
:subsection {:latex "Vectors (conj, pop, \\& peek at end)"
:html "Vectors (conj, pop, & peek at end)"}
:table [["Create" :cmds '["[]" vector vec vector-of
"(1.4)" mapv filterv]]
["Examine" :cmds '[{:latex "\\cmd{(my-vec idx)} $\\to$ \\cmd{(}",
:html "<code>(my-vec idx)</code> → <code>("}
nth
{:latex " \\cmd{my-vec idx)}",
:html " my-vec idx)</code>"}
get peek
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html\\#indexOf\\%28java.lang.Object\\%29}{.indexOf}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html#indexOf%28java.lang.Object%29\">.indexOf</a>"}
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html\\#lastIndexOf\\%28java.lang.Object\\%29}{.lastIndexOf}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html#lastIndexOf%28java.lang.Object%29\">.lastIndexOf</a>"}
]]
[{:html "'Change'", :latex "`Change'"}
:cmds '[assoc pop subvec replace conj rseq]]
["Ops" :cmds '["(1.4)" reduce-kv]]]
:subsection "Sets"
:table [["Create" :cmds '[{:latex "\\#\\{\\}", :html "#{}"}
set hash-set sorted-set sorted-set-by
{:latex "\\textmd{\\textsf{(clojure.data.avl/)}}",
:html "(clojure.data.avl/)"}
clojure.data.avl/sorted-set
clojure.data.avl/sorted-set-by
{:latex "\\textmd{\\textsf{(flatland.ordered.set/)}}",
:html "(flatland.ordered.set/)"}
flatland.ordered.set/ordered-set]]
["Examine" :cmds '[{:latex "\\cmd{(my-set item)} $\\to$ \\cmd{(}",
:html "<code>(my-set item)</code> → <code>("}
get
{:latex " \\cmd{my-set item)}",
:html " my-set item)</code>"}
contains?]]
[{:html "'Change'", :latex "`Change'"}
:cmds '[conj disj]]
["Set ops"
:cmds '[{:latex "\\textmd{\\textsf{(clojure.set/)}}",
:html "(clojure.set/)"}
clojure.set/union clojure.set/difference
clojure.set/intersection clojure.set/select
{:latex "\\textmd{\\textsf{See also Relations}}",
:html "See also Relations"}
]]
["Test"
:cmds '[{:latex "\\textmd{\\textsf{(clojure.set/)}}",
:html "(clojure.set/)"}
clojure.set/subset? clojure.set/superset?]]
["Sorted sets" :cmds '[rseq subseq rsubseq]]
]
:subsection "Maps"
:table [["Create"
:cmds '[{:latex "\\{\\}", :html "{}"}
hash-map array-map zipmap
sorted-map sorted-map-by bean
frequencies group-by
{:latex "\\textmd{\\textsf{(clojure.set/)}}",
:html "(clojure.set/)"}
clojure.set/index
{:latex "\\textmd{\\textsf{(clojure.data.avl/)}}",
:html "(clojure.data.avl/)"}
clojure.data.avl/sorted-map
clojure.data.avl/sorted-map-by
{:latex "\\textmd{\\textsf{(flatland.ordered.map/)}}",
:html "(flatland.ordered.map/)"}
flatland.ordered.map/ordered-map
{:latex "\\textmd{\\textsf{(clojure.data.priority-map/)}}",
:html "(clojure.data.priority-map/)"}
clojure.data.priority-map/priority-map
{:latex "\\textmd{\\textsf{(flatland.useful.map/)}}",
:html "(flatland.useful.map/)"}
flatland.useful.map/ordering-map
]]
["Examine"
:cmds '[
{:latex "\\cmd{(my-map k)} $\\to$ \\cmd{(}",
:html "<code>(my-map k)</code> → <code>("}
get
{:latex " \\cmd{my-map k)}",
:html " my-map k)</code>"}
"also"
{:latex "\\cmd{(:key my-map)} $\\to$ \\cmd{(}",
:html "<code>(:key my-map)</code> → <code>("}
get
{:latex " \\cmd{my-map :key)}",
:html " my-map :key)</code>"}
get-in contains? find keys vals
]]
[{:html "'Change'", :latex "`Change'"}
:cmds '[assoc assoc-in dissoc merge
merge-with select-keys update-in
{:latex "\\textmd{\\textsf{(clojure.set/)}}",
:html "(clojure.set/)"}
clojure.set/rename-keys
clojure.set/map-invert
{:latex "\\textmd{\\textsf{GitHub:}}",
:html "GitHub:"}
{:latex "\\href{http://github.com/weavejester/medley}{Medley}"
:html "<a href=\"http://github.com/weavejester/medley\">Medley</a>"}
]]
["Ops" :cmds '["(1.4)" reduce-kv]]
["Entry" :cmds '[key val]]
["Sorted maps" :cmds '[rseq subseq rsubseq]]]
]
:column
[:box "yellow"
:subsection {:latex "Queues (conj at end, peek \\& pop from beginning)"
:html "Queues (conj at end, peek & pop from beginning)"}
:table [["Create"
:cmds '[ "clojure.lang.PersistentQueue/EMPTY"
"(no literal syntax or constructor fn)" ]]
["Examine" :cmds '[ peek ]]
["'Change'" :cmds '[ conj pop ]]]
:subsection "Relations (set of maps, each with same keys, aka rels)"
:table [["Rel algebra"
:cmds '[
{:latex "\\textmd{\\textsf{(clojure.set/)}}",
:html "(clojure.set/)"}
clojure.set/join clojure.set/select
clojure.set/project clojure.set/union
clojure.set/difference clojure.set/intersection
clojure.set/index
clojure.set/rename
]]]
:subsection {:latex "Transients (\\href{http://clojure.org/transients}{clojure.org/transients})"
:html "Transients (<a href=\"http://clojure.org/transients\">clojure.org/transients</a>)"}
:table [["Create" :cmds '[transient persistent!]]
["Change" :cmds-with-frenchspacing
'[conj! pop! assoc! dissoc! disj!
{:latex "\\textmd{\\textsf{Note: always use return value for later changes, never original!}}",
:html "Note: always use return value for later changes, never original!"}]]]
:subsection "Misc"
:table [["Compare" :cmds '[= identical? not= not compare
clojure.data/diff]]
["Test" :cmds '[true? false? instance? nil?
"(1.6)" some?]]]
]
[:box "orange"
:section "Sequences"
:subsection "Creating a Lazy Seq"
:table [["From collection" :cmds '[seq vals keys rseq
subseq rsubseq sequence]]
["From producer fn" :cmds '[lazy-seq repeatedly iterate]]
["From constant" :cmds '[repeat range]]
["From other" :cmds '[file-seq line-seq resultset-seq
re-seq tree-seq xml-seq
iterator-seq enumeration-seq]]
["From seq" :cmds '[keep keep-indexed]]]
:subsection "Seq in, Seq out"
:table [["Get shorter" :cmds '[distinct filter remove
take-nth for]]
["Get longer" :cmds '[cons conj concat lazy-cat mapcat
cycle interleave interpose]]
["Tail-items" :cmds '[rest nthrest next fnext nnext
drop drop-while take-last for]]
["Head-items" :cmds '[take take-while butlast
drop-last for]]
[{:html "'Change'", :latex "`Change'"}
:cmds '[conj concat distinct flatten group-by
partition partition-all partition-by
split-at split-with filter remove
replace shuffle]]
["Rearrange" :cmds '[reverse sort sort-by compare]]
["Process items" :cmds '[map pmap map-indexed
mapcat for replace seque]]]
:subsection "Using a Seq"
:table [["Extract item" :cmds '[first second last rest next
ffirst nfirst fnext
nnext nth nthnext rand-nth
when-first max-key min-key]]
["Construct coll" :cmds '[zipmap into reduce reductions
set vec into-array to-array-2d
"(1.4)" mapv filterv]]
["Pass to fn" :cmds '[apply]]
["Search" :cmds '[some filter]]
["Force evaluation" :cmds '[doseq dorun doall]]
["Check for forced" :cmds '[realized?]]]
]
[:box "green"
:subsection "Zippers (clojure.zip/)"
:table [["Create" :cmds '[clojure.zip/zipper
clojure.zip/seq-zip
clojure.zip/vector-zip
clojure.zip/xml-zip]]
["Get loc" :cmds '[clojure.zip/up
clojure.zip/down clojure.zip/left
clojure.zip/right
clojure.zip/leftmost
clojure.zip/rightmost]]
["Get seq" :cmds '[clojure.zip/lefts clojure.zip/rights
clojure.zip/path clojure.zip/children]]
[{:html "'Change'", :latex "`Change'"}
:cmds '[clojure.zip/make-node clojure.zip/replace
clojure.zip/edit clojure.zip/insert-child
clojure.zip/insert-left clojure.zip/insert-right
clojure.zip/append-child clojure.zip/remove]]
["Move" :cmds '[clojure.zip/next clojure.zip/prev]]
["Misc" :cmds '[clojure.zip/root clojure.zip/node
clojure.zip/branch? clojure.zip/end?]]]
]
[:box "magenta"
:section "IO"
:table [
; ["to/from ..."
[{:latex "\\begin{tabular}[t]{@{}l@{}} to/from \\\\ ... \\end{tabular}"
:html "to/from ..."}
:cmds '[spit slurp
{:latex "\\textmd{\\textsf{(to writer/from reader, Socket, string with file name, URI, etc.)}}",
:html "(to writer/from reader, Socket, string with file name, URI, etc.)"}
]]
["to *out*" :cmds '[pr prn print printf println
newline
{:latex "\\textmd{\\textsf{(clojure.pprint/)}}",
:html "(clojure.pprint/)"}
clojure.pprint/print-table]]
["to writer" :cmds '[{:latex "\\textmd{\\textsf{(clojure.pprint/)}}",
:html "(clojure.pprint/)"}
clojure.pprint/pprint
clojure.pprint/cl-format
{:latex "\\textmd{\\textsf{also:}}",
:html "also:"}
"(binding [*out* writer] ...)"]]
["to string" :cmds '[format with-out-str pr-str
prn-str print-str println-str]]
["from *in*" :cmds '[read-line
{:latex "\\textmd{\\textsf{(clojure.tools.reader.edn/)}}",
:html "(clojure.tools.reader.edn/)"}
clojure.tools.reader.edn/read
]]
["from reader" :cmds '[line-seq
{:latex "\\textmd{\\textsf{(clojure.tools.reader.edn/)}}",
:html "(clojure.tools.reader.edn/)"}
clojure.tools.reader.edn/read
{:latex "\\textmd{\\textsf{also:}}",
:html "also:"}
"(binding [*in* reader] ...)"
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/io/Reader.html}{java.io.Reader}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/io/Reader.html\">java.io.Reader</a>"}
]]
["from string" :cmds '[
with-in-str
{:latex "\\textmd{\\textsf{(clojure.tools.reader.edn/)}}",
:html "(clojure.tools.reader.edn/)"}
clojure.tools.reader.edn/read-string
]]
["Open" :cmds '[with-open
; {:latex "\\textmd{\\textsf{string:}}",
; :html "string:"}
; with-out-str with-in-str
{:latex "\\textmd{\\textsf{(clojure.java.io/)}}",
:html "(clojure.java.io/)"}
{:latex "\\textmd{\\textsf{text:}}",
:html "text:"}
clojure.java.io/reader clojure.java.io/writer
{:latex "\\textmd{\\textsf{binary:}}",
:html "binary:"}
clojure.java.io/input-stream clojure.java.io/output-stream
]]
["Binary" :cmds '["(.write ostream byte-arr)"
"(.read istream byte-arr)"
; "(javadoc java.io.OutputStream)"
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html}{java.io.OutputStream}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html\">java.io.OutputStream</a>"}
; "java.io.InputStream"
{:latex "\\href{http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html}{java.io.InputStream}"
:html "<a href=\"http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html\">java.io.InputStream</a>"}
{:latex "\\textmd{\\textsf{GitHub:}}",
:html "GitHub:"}
{:latex "\\href{http://github.com/ztellman/gloss}{gloss}"
:html "<a href=\"http://github.com/ztellman/gloss\">gloss</a>"}
{:latex "\\href{http://github.com/rosejn/byte-spec}{byte-spec}"
:html "<a href=\"http://github.com/rosejn/byte-spec\">byte-spec</a>"}
]]
["Misc" :cmds '[flush "(.close s)" file-seq
*in* *out* *err*
{:latex "\\textmd{\\textsf{(clojure.java.io/)}}",
:html "(clojure.java.io/)"}
clojure.java.io/file
clojure.java.io/copy
clojure.java.io/delete-file
clojure.java.io/resource
clojure.java.io/as-file
clojure.java.io/as-url
clojure.java.io/as-relative-path
{:latex "\\textmd{\\textsf{GitHub:}}",
:html "GitHub:"}
{:latex "\\href{http://github.com/Raynes/fs}{fs}"
:html "<a href=\"http://github.com/Raynes/fs\">fs</a>"}
]]
["Data readers" :cmds '["(1.4)" *data-readers*
default-data-readers
"(1.5)" *default-data-reader-fn*]]
]
]
]
:page [:column
[:box "blue"
:section "Functions"
:table [["Create" :cmds '[fn defn defn- definline identity
constantly memfn comp complement
partial juxt memoize fnil every-pred
some-fn]]
["Call" :cmds '[apply -> ->> trampoline
"(1.5)" as-> cond-> cond->>
some-> some->>]]
["Test" :cmds '[fn? ifn?]]]
]
[:box "orange"
:section {:latex "Abstractions (\\href{https://github.com/cemerick/clojure-type-selection-flowchart}{Clojure type selection flowchart})"
:html "Abstractions (<a href=\"https://github.com/cemerick/clojure-type-selection-flowchart\">Clojure type selection flowchart</a>)"}
:subsection {:latex "Protocols (\\href{http://clojure.org/protocols}{clojure.org/protocols})"
:html "Protocols (<a href=\"http://clojure.org/protocols\">clojure.org/protocols</a>)"}
:table [
["Define" :cmds '[
{:latex "\\cmd{(}"
:html "<code>(</code>"}
defprotocol
{:latex "\\cmd{Slicey (slice [at]))}"
:html "<code>Slicey (slice [at]))</code>"}
]]
["Extend" :cmds '[
{:latex "\\cmd{(}"
:html "<code>(</code>"}
extend-type
{:latex "\\cmd{String Slicey (slice [at] ...))}"
:html "<code>String Slicey (slice [at] ...))</code>"}
]]
["Extend null" :cmds '[
{:latex "\\cmd{(}"
:html "<code>(</code>"}
extend-type
{:latex "\\cmd{nil Slicey (slice [\\_] nil))}"
:html "<code>nil Slicey (slice [_] nil))</code>"}
]]
["Reify" :cmds '[
{:latex "\\cmd{(}"
:html "<code>(</code>"}
reify
{:latex "\\cmd{Slicey (slice [at] ...))}"
:html "<code>Slicey (slice [at] ...))</code>"}
]]
["Test" :cmds '[satisfies? extends?]]
["Other" :cmds '[extend extend-protocol extenders]]
]
:subsection {:latex "Records (\\href{http://clojure.org/datatypes}{clojure.org/datatypes})"
:html "Records (<a href=\"http://clojure.org/datatypes\">clojure.org/datatypes</a>)"}
:table [
["Define" :cmds '[
{:latex "\\cmd{(}"
:html "<code>(</code>"}
defrecord
{:latex "\\cmd{Pair [h t])}"
:html "<code>Pair [h t])</code>"}
]]
["Access" :cmds '[
{:latex "\\cmd{(:h (Pair. 1 2))} $\\to$ \\cmd{1}"
:html "<code>(:h (Pair. 1 2))</code> → <code>1</code>"}
]]
["Create" :cmds '[
Pair. ->Pair map->Pair
]]
["Test" :cmds '[record?]]
]
:subsection {:latex "Types (\\href{http://clojure.org/datatypes}{clojure.org/datatypes})"
:html "Types (<a href=\"http://clojure.org/datatypes\">clojure.org/datatypes</a>)"}
:table [
["Define" :cmds '[
{:latex "\\cmd{(}"
:html "<code>(</code>"}
deftype
{:latex "\\cmd{Pair [h t])}"
:html "<code>Pair [h t])</code>"}
]]
["Access" :cmds '[
{:latex "\\cmd{(.h (Pair. 1 2))} $\\to$ \\cmd{1}"
:html "<code>(.h (Pair. 1 2))</code> → <code>1</code>"}
]]
["Create" :cmds '[Pair. ->Pair]]
["With methods" :cmds '[
{:latex "\\begin{tabular}[c]{@{}l@{}} \\cmd{(}"
:html "<code>(</code>"}
deftype
{:latex "\\cmd{Pair [h t]} \\\\ \\ \\ \\cmd{Object} \\\\ \\ \\ \\cmd{(toString [this] (str \"<\" h \",\" t \">\")))}\\end{tabular}"
:html "<code>Pair [h t]<br> Object<br> (toString [this] (str \"<\" h \",\" t \">\")))</code>"}
]]
]
:subsection {:latex "Multimethods (\\href{http://clojure.org/multimethods}{clojure.org/multimethods})"
:html "Multimethods (<a href=\"http://clojure.org/multimethods\">clojure.org/multimethods</a>)"}
:table [
["Define" :cmds '[
{:latex "\\cmd{(}"
:html "<code>(</code>"}
defmulti
{:latex "\\cmd{my-mm dispatch-fn)}"
:html "<code>my-mm dispatch-fn)</code>"}
]]
["Method define" :cmds '[
{:latex "\\cmd{(}"
:html "<code>(</code>"}
defmethod
{:latex "\\cmd{my-mm :dispatch-value [args] ...)}"
:html "<code>my-mm :dispatch-value [args] ...)</code>"}
]]
; ["Create" :cmds '[defmulti defmethod]]
["Dispatch" :cmds '[get-method methods]]
["Remove" :cmds '[remove-method remove-all-methods]]
["Prefer" :cmds '[prefer-method prefers]]
["Relation" :cmds '[derive underive isa? parents ancestors
descendants make-hierarchy]]]
]
[:box "green"
:section "Macros"
:table [["Create" :cmds '[defmacro definline]]
["Debug" :cmds '[macroexpand-1 macroexpand
{:latex "\\textmd{\\textsf{(clojure.walk/)}}",
:html "(clojure.walk/)"}
clojure.walk/macroexpand-all]]
["Branch" :cmds '[and or when when-not when-let
when-first if-not if-let cond condp
case "(1.6)" when-some if-some]]
["Loop" :cmds '[for doseq dotimes while]]
["Arrange" :cmds '[.. doto -> ->>
"(1.5)" as-> cond-> cond->>
some-> some->>]]
["Scope" :cmds '[binding locking time
[:common-prefix with-
in-str local-vars open out-str
precision redefs redefs-fn]]]
["Lazy" :cmds '[lazy-cat lazy-seq delay]]
["Doc." :cmds '[assert comment clojure.repl/doc]]]
]
[:box "yellow"
:section {:latex "Reader Macros (\\href{http://clojure.org/reader\\#The\\%20Reader--Macro\\%20characters}{clojure.org/reader})"
:html "Reader Macros (<a href=\"http://clojure.org/reader#The%20Reader--Macro%20characters\">clojure.org/reader</a>)"}
:table [[{:latex "\\cmd{'}",
:html "<code>'</code>"}
:cmds '[{:latex "\\href{http://clojure.org/special\\_forms\\#quote}{quote}: 'form $\\to$ (",
:html "<a href=\"http://clojure.org/special_forms#quote\">quote</a>: <code>'<var>form</var></code> → <code>(</code>"}
quote
{:latex "form)",
:html "<code><var>form</var>)</code>"}]]
[{:latex "\\cmd{\\textbackslash}",
:html "<code>\\</code>"}
:str "Character literal"]
[{:latex "\\cmd{;}",
:html "<code>;</code>"}
:str "Single line comment"]
[{:latex "\\cmd{\\^{}}",
:html "<code>^</code>"}
:str "Metadata (see Metadata section)"]
[{:latex "\\cmd{@}",
:html "<code>@</code>"}
:cmds '[{:latex "Deref: @form $\\to$ (",
:html "Deref: <code>@<var>form</var></code> → <code>(</code>"}
deref
{:latex "form)",
:html "<code><var>form</var>)</code>"}]]
[{:latex "\\cmd{`}",
:html "<code>`</code>"}
:cmds '[{:latex "\\href{http://clojure.org/reader\\#syntax-quote}{Syntax-quote}"
:html "<a href=\"http://clojure.org/reader#syntax-quote\">Syntax-quote</a>"}]]
[{:latex "\\cmd{\\textasciitilde}",
:html "<code>~</code>"}
:cmds '[{:latex "\\href{http://clojure.org/reader\\#syntax-quote}{Unquote}"
:html "<a href=\"http://clojure.org/reader#syntax-quote\">Unquote</a>"}]]
[{:latex "\\cmd{\\textasciitilde@}",
:html "<code>~@</code>"}
:cmds '[{:latex "\\href{http://clojure.org/reader\\#syntax-quote}{Unquote-splicing}"
:html "<a href=\"http://clojure.org/reader#syntax-quote\">Unquote-splicing</a>"}]]
[{:latex "\\cmd{\\#\"}\\textit{p}\\cmd{\"}",
:html "<code>#\"<var>p</var>\"</code>"}
:str {:latex "Regex Pattern \\textit{p} (see Strings/Regex section)",
:html "Regex Pattern <var>p</var> (see Strings/Regex section)"}]
[{:latex "\\cmd{\\#$'$}",
:html "<code>#'</code>"}
:cmds '[{:latex "Var-quote \\#$'$x $\\to$ (",
:html "Var-quote: <code>#'<var>x</var></code> → <code>(</code>"}
var
{:latex "x)",
:html "<code><var>x</var>)</code>"}]]
[{:latex "\\cmd{\\#()}",
:html "<code>#()</code>"}
:cmds [
{:latex "\\href{http://clojure.org/reader\\#The\\%20Reader--Macro\\%20characters}{Anonymous function literal}:"
:html "<a href=\"http://clojure.org/reader#The%20Reader--Macro%20characters\">Anonymous function literal</a>:"}
{:latex "\\#(...) $\\to$ (fn [args] (...))",
:html "<code>#(...)</code> → <code>(fn [args] (...))</code>"}]]
[{:latex "\\cmd{\\#\\_}",
:html "<code>#_</code>"}
:str "Ignore next form"]]
]
[:box "red"
:section {:latex "Metadata (\\href{http://clojure.org/reader\\#The\\%20Reader--Macro\\%20characters}{clojure.org/reader}, \\href{http://clojure.org/special\\_forms}{special\\_forms})"
:html "Metadata (<a href=\"http://clojure.org/reader#The%20Reader--Macro%20characters\">clojure.org/reader</a>, <a href=\"http://clojure.org/special_forms\">special_forms</a>)"}
:table [
["General" :cmds [{:latex "\\cmd{\\^{}\\{:key1 val1 :key2 val2 ...\\}}"
:html "<code>^{:key1 val1 :key2 val2 ...}</code>"}
]]
["Abbrevs" :cmds [{:latex "\\cmd{\\^{}Type} $\\to$ \\cmd{\\^{}\\{:tag Type\\}},
\\cmd{\\^{}:key} $\\to$ \\cmd{\\^{}\\{:key true\\}}"
:html
"<code>^Type</code> → <code>^{:tag Type}</code><br>
<code>^:key</code> → <code>^{:key true}</code>"}
]]
["Common" :cmds [{:latex (str
"\\cmd{\\^{}:dynamic} "
"\\cmd{\\^{}:private} "
"\\cmd{\\^{}:doc} "
"\\cmd{\\^{}:const}"
)
:html (str
"<code>"
"^:dynamic "
"^:private "
"^:doc "
"^:const"
"</code>")}
]]
["Examples" :cmds '[
{:latex "\\cmd{(defn \\^{}:private \\^{}String my-fn ...)}"
:html "<code>(defn ^:private ^String my-fn ...)</code>"}
{:latex " \\ \\ \\ " ; fragile hack to get 2nd example to start on next line
:html " <br>"}
{:latex "\\cmd{(def \\^{}:dynamic *dyn-var* val)}"
:html "<code>(def ^:dynamic *dyn-var* val)</code>"}
]]
;; ["Others" :cmds [
;; {:latex (str
;; "\\cmd{:added}"
;; " \\cmd{:author}"
;; " \\cmd{:doc} "
;; " \\cmd{:arglists} "
;; " \\cmd{:inline}"
;; " \\cmd{:inline-arities}"
;; " \\cmd{:macro}"
;; ; " (examples in Clojure source)"
;; ; " (see Clojure source for examples. Can use arbitrary keys for your own purposes.)"
;; )
;; :html (str
;; "<code>"
;; ":added"
;; " :author"
;; " :arglists "
;; " :doc "
;; " :inline"
;; " :inline-arities"
;; " :macro"
;; "</code>"
;; ; " (examples in Clojure source)"
;; ; " (see Clojure source for examples. Can use arbitrary keys for your own purposes.)"
;; )}
;; ]]
["On Vars" :cmds '[meta with-meta vary-meta
alter-meta! reset-meta!
clojure.repl/doc
clojure.repl/find-doc test]]
]
]
:column
[:box "red"
:section {:latex "Special Forms (\\href{http://clojure.org/special\\_forms}{clojure.org/special\\_forms})"
:html "Special Forms (<a href=\"http://clojure.org/special_forms\">clojure.org/special_forms</a>)"}
:cmds-one-line '[def if do let letfn quote var fn loop
recur set! throw try monitor-enter monitor-exit]
:table [[{:latex "\\begin{tabular}[t]{@{}l@{}} Binding Forms / \\\\ Destructuring \\end{tabular}"
:html "Binding Forms / Destructuring"}
:cmds '[
{:latex "(\\href{http://clojure.org/special\\_forms\\#binding-forms}{examples})"
:html "(<a href=\"http://clojure.org/special_forms#binding-forms\">examples</a>)"}
let fn defn defmacro
loop for doseq if-let when-let
"(1.6)" if-some when-some]]
]
]
[:box "blue2"
:section {:latex "Vars and global environment (\\href{http://clojure.org/vars}{clojure.org/vars})"
:html "Vars and global environment (<a href=\"http://clojure.org/vars\">clojure.org/vars</a>)"}
:table [["Def variants" :cmds '[def defn defn- definline defmacro
defmethod defmulti defonce
defrecord]]
["Interned vars" :cmds '[declare intern binding
find-var var]]
["Var objects" :cmds '[with-local-vars var-get var-set
alter-var-root var? bound?
thread-bound?]]
["Var validators" :cmds '[set-validator! get-validator]]
;; Now covered in Metadata section
;; ["Var metadata" :cmds '[meta clojure.repl/doc
;; clojure.repl/find-doc test]]
]
]
[:box "yellow"
:section "Namespace"
:table [["Current" :cmds '[*ns*]]
["Create/Switch" :cmds '[{:latex "(\\href{http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html}{tutorial})"
:html "(<a href=\"http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html\">tutorial</a>)"}
ns in-ns create-ns]]
["Add" :cmds '[alias def import intern refer]]
["Find" :cmds '[all-ns find-ns]]
;; ["Examine" :cmds '[ns-name ns-aliases ns-map
;; ns-interns ns-publics ns-refers
;; ns-imports]]
["Examine" :cmds '[[:common-prefix ns-
name aliases map interns publics
refers imports]]]
["From symbol" :cmds '[resolve ns-resolve namespace
the-ns]]
["Remove" :cmds '[ns-unalias ns-unmap remove-ns]]]
]
[:box "green"
:section "Loading"
:table [["Load libs" :cmds '[{:latex "(\\href{http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html}{tutorial})"
:html "(<a href=\"http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html\">tutorial</a>)"}
require use import refer]]
["List loaded" :cmds '[loaded-libs]]
["Load misc" :cmds '[load load-file load-reader
load-string]]]
]
[:box "magenta"
:section "Concurrency"
:table [["Atoms" :cmds '[atom swap! reset! compare-and-set!]]
["Futures" :cmds '[future
[:common-prefix future-
call done? cancel cancelled?]
future?]]
["Threads" :cmds '[bound-fn bound-fn*
[:common-suffix -thread-bindings
get push pop]
thread-bound?]]
["Misc" :cmds '[locking pcalls pvalues pmap seque
promise deliver]]]
:subsection {:latex "Refs and Transactions (\\href{http://clojure.org/refs}{clojure.org/refs})"
:html "Refs and Transactions (<a href=\"http://clojure.org/refs\">clojure.org/refs</a>)"}
:table [["Create" :cmds '[ref]]
["Examine"
:cmds '[deref "@"
{:latex "\\textmd{\\textsf{(@form $\\to$ (deref form))}}",
:html "(<code>@<var>form</var></code> → <code>(deref <var>form</var>)</code>)"}]]
["Transaction" :cmds '[sync dosync io!]]
["In transaction" :cmds '[ensure ref-set alter commute]]
["Validators" :cmds '[set-validator! get-validator]]
["History" :cmds '[ref-history-count
[:common-prefix-suffix
ref- -history min max]]]]
:subsection {:latex "Agents and Asynchronous Actions (\\href{http://clojure.org/agents}{clojure.org/agents})"
:html "Agents and Asynchronous Actions (<a href=\"http://clojure.org/agents\">clojure.org/agents</a>)"}
:table [["Create" :cmds '[agent]]
["Examine" :cmds '[agent-error]]
["Change state" :cmds '[send send-off restart-agent
"(1.5)"
send-via set-agent-send-executor!
set-agent-send-off-executor!]]
["Block waiting" :cmds '[await await-for]]
["Ref validators" :cmds '[set-validator! get-validator]]
["Watchers" :cmds '[add-watch remove-watch]]
["Thread handling" :cmds '[shutdown-agents]]
["Error" :cmds '[error-handler set-error-handler!
error-mode set-error-mode!]]
["Misc" :cmds '[*agent* release-pending-sends]]]
]
[:box "orange"
:section {:latex "Java Interoperation (\\href{http://clojure.org/java\\_interop}{clojure.org/java\\_interop})"
:html "Java Interoperation (<a href=\"http://clojure.org/java_interop\">clojure.org/java_interop</a>)"}
:table [["General" :cmds '[.. doto "Classname/" "Classname."
new bean comparator enumeration-seq
import iterator-seq memfn set! class
class? bases supers type
gen-class gen-interface definterface]]
["Cast" :cmds '[boolean byte short char int long
float double bigdec bigint num cast
biginteger]]
["Exceptions" :cmds '[throw try catch finally
clojure.repl/pst
"(1.4)" ex-info ex-data]]]
:subsection "Arrays"
:table [["Create" :cmds '[make-array
[:common-suffix -array object
boolean byte short char int long
float double]
aclone to-array to-array-2d into-array]]
["Use" :cmds '[aget aset
[:common-prefix aset- boolean byte short
char int long float double]
alength amap areduce]]
;; TBD: This would be a good place to give an
;; example like ^"[Ljava.lang.BigInteger", yes?
;; Also the cast ^objects? Is there a doc page
;; for that?
["Cast" :cmds '[booleans bytes shorts chars
ints longs floats doubles]]
]
:subsection {:latex "Proxy (\\href{https://github.com/cemerick/clojure-type-selection-flowchart}{Clojure type selection flowchart})"
:html "Proxy (<a href=\"https://github.com/cemerick/clojure-type-selection-flowchart\">Clojure type selection flowchart</a>)"}