-
Notifications
You must be signed in to change notification settings - Fork 15
/
worksheet.clj
3161 lines (2757 loc) · 161 KB
/
worksheet.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
;; gorilla-repl.fileformat = 1
;; **
;;; # Clojinc (The Gorilla REPL worksheet version)
;;;
;; **
;; @@
;; clojinc
;; Steps toward clojure, starting from zero.
;; by Lee Spector <[email protected]>, 2011-2017
;; Version (date): 20170914
;; This file is a saved, re-executable Clojure REPL (Read Eval Print Loop)
;; session, with minimal comments and occasional problem sets. It is intended
;; to serve as the starting-point for semi-independent learning of the Clojure
;; programming language, for people who have at least some minimal experience
;; with at least one (any) programming language. No help is provided here for
;; getting a Clojure implementation/REPL up and running; consult the online
;; resources listed below, or search the web, if you need help with that.
;; The format of this file is alternating Clojure expressions with
;; commented-out output (including both the output produced by explicit print
;; statements and the values returned by the evaluated expressions). You should
;; be able to proceed through the file, evaluating an expression at a time, and
;; if you do this you should get the same output (or similar output, in cases
;; that involve nondeterminism). In many cases later expressions rely on having
;; evaluated earlier expressions in the file.
;; The material in this file is informal and idiosyncratic in its coverage,
;; leaving out many things that other Clojure introductions include and revealing
;; the Lisp-oriented bias of the author. The intention is just to lead beginners
;; deeply enough into Clojure territory for them to proceed in other directions
;; on their own.
;; More specifically, we begin with simple expressions for arithmetic and list
;; manipulation, introduce facilities for defining functions and macros, and give
;; progressively more complex examples of definitions that involve many of
;; Clojure's data structures including lists, vectors, maps, and sets. Among the
;; applications used for examples and problem sets are grammar-driven text
;; generation, genetic programming, and simple graphics. We also demonstrate
;; alternatives for defining iterative and recursive algorithms and briefly touch
;; upon topics ranging from debugging and profiling to file I/O and concurrency.
;; Many things are introduced here without explanation. My suggestion is that
;; you observe the output that is provided here, look things up in online resources
;; and in documentation that may be available in your Clojure environment, and,
;; most crucially, experiment with variations of the expressions presented here.
;; The problem sets are prods for further experimentation but it is best to
;; experiment continuously. Some of the problems provided here are easy, some are
;; quite hard, and many could be completed/varied/extended in several different
;; ways.
;; Potentially useful online resources include:
;; http://clojure.org
;; http://dev.clojure.org/display/doc/Getting+Started
;; http://groups.google.com/group/clojure
;; http://4clojure.com
;; http://clojuredocs.org
;; http://www.clojure-toolbox.com
;; http://www.clojureatlas.com
;; http://alexott.net/en/clojure/video.html
;; http://planet.clojure.in/
;; Most of the outputs in clojinc were created using clojure version 1.3 in a
;; REPL started with Leiningen 1.7.1 (https://github.com/technomancy/leiningen)
;; and using Java 1.6.0_33. (A few were left from an earlier version, for which
;; Clooj (https://github.com/arthuredelstein/clooj) was used.
;; create the namespace within which we'll work
(ns clojinc.core)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
;; @@
0
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>0</span>","value":"0"}
;; <=
;; @@
(inc 0)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>1</span>","value":"1"}
;; <=
;; @@
(inc (inc 0))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>2</span>","value":"2"}
;; <=
;; @@
(dec 2)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>1</span>","value":"1"}
;; <=
;; @@
(dec 0)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>-1</span>","value":"-1"}
;; <=
;; @@
(+ 1 1)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>2</span>","value":"2"}
;; <=
;; @@
+
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>#function[clojure.core/+]</span>","value":"#function[clojure.core/+]"}
;; <=
;; @@
(* 23 13)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>299</span>","value":"299"}
;; <=
;; @@
(+ 1 (* 23 13))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>300</span>","value":"300"}
;; <=
;; @@
(+ (* 2 2) (- 10 9))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>5</span>","value":"5"}
;; <=
;; @@
(* 2 2 2 2)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>16</span>","value":"16"}
;; <=
;; @@
(/ 25 5)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>5</span>","value":"5"}
;; <=
;; @@
(/ 38 4)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-ratio'>19/2</span>","value":"19/2"}
;; <=
;; @@
(+ 1/3 1/3)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-ratio'>2/3</span>","value":"2/3"}
;; <=
;; @@
(+ (/ 1.0 3.0)
(/ 1.0 3.0))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-double'>0.6666666666666666</span>","value":"0.6666666666666666"}
;; <=
;; @@
(/ 23 0) ;; nope
;; @@
;; @@
(* 123456789 987654321 999999999 12345678987654321)
;; @@
;; @@
(* 123456789M 987654321 999999999 12345678987654321)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-bigdecimal'>1505341120331325629973976373036705875152651M</span>","value":"1505341120331325629973976373036705875152651M"}
;; <=
;; @@
(sqrt (* 2 2 2 2))
;; @@
;; @@
(Math/sqrt (* 2 2 2 2)) ;; from java.lang.Math
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-double'>4.0</span>","value":"4.0"}
;; <=
;; @@
(Math/sqrt -4) ;; nope
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-double'>NaN</span>","value":"NaN"}
;; <=
;; @@
(Math/log 2)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-double'>0.6931471805599453</span>","value":"0.6931471805599453"}
;; <=
;; @@
(Math/sqrt 1000000)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-double'>1000.0</span>","value":"1000.0"}
;; <=
;; @@
Math/PI ;; this is a java interop form, for the PI static field of the Math class
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-double'>3.141592653589793</span>","value":"3.141592653589793"}
;; <=
;; @@
(def my-favorite-number 23)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/my-favorite-number</span>","value":"#'clojinc.core/my-favorite-number"}
;; <=
;; @@
my-favorite-number
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>23</span>","value":"23"}
;; <=
;; @@
(* my-favorite-number Math/PI)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-double'>72.25663103256524</span>","value":"72.25663103256524"}
;; <=
;; @@
(use 'clojure.inspector)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
;; @@
(inspect my-favorite-number)
; < window opens in the clojure.main application>
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>#object[javax.swing.JFrame 0x78df83 "javax.swing.JFrame[frame0,0,23,400x400,invalid,layout=java.awt.BorderLayout,title=Clojure Inspector,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,22,400x378,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]"]</span>","value":"#object[javax.swing.JFrame 0x78df83 \"javax.swing.JFrame[frame0,0,23,400x400,invalid,layout=java.awt.BorderLayout,title=Clojure Inspector,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,22,400x378,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]\"]"}
;; <=
;; @@
;; Problem Set 1:
;; - Write an expression that calculates the number of seconds in a year.
;; - Define diameter to be some number and write expression that calculates the area
;; of a circle with that diameter.
;; - Write arithmetic expressions for other formulas that you remember from high school
;; (or look some up if you don't remember any!).
;; @@
;; @@
woof
;; @@
;; @@
;; a single quote inhibits evaluation
'woof
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-symbol'>woof</span>","value":"woof"}
;; <=
;; @@
(cons 'woof '(bow wow))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>woof</span>","value":"woof"},{"type":"html","content":"<span class='clj-symbol'>bow</span>","value":"bow"},{"type":"html","content":"<span class='clj-symbol'>wow</span>","value":"wow"}],"value":"(woof bow wow)"}
;; <=
;; @@
(cons '(howl) '(at the moon))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>howl</span>","value":"howl"}],"value":"(howl)"},{"type":"html","content":"<span class='clj-symbol'>at</span>","value":"at"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>moon</span>","value":"moon"}],"value":"((howl) at the moon)"}
;; <=
;; @@
(def my-favorite-list '(fe fi fo fum))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/my-favorite-list</span>","value":"#'clojinc.core/my-favorite-list"}
;; <=
;; @@
my-favorite-list
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>fe</span>","value":"fe"},{"type":"html","content":"<span class='clj-symbol'>fi</span>","value":"fi"},{"type":"html","content":"<span class='clj-symbol'>fo</span>","value":"fo"},{"type":"html","content":"<span class='clj-symbol'>fum</span>","value":"fum"}],"value":"(fe fi fo fum)"}
;; <=
;; @@
(first my-favorite-list)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-symbol'>fe</span>","value":"fe"}
;; <=
;; @@
(rest my-favorite-list)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>fi</span>","value":"fi"},{"type":"html","content":"<span class='clj-symbol'>fo</span>","value":"fo"},{"type":"html","content":"<span class='clj-symbol'>fum</span>","value":"fum"}],"value":"(fi fo fum)"}
;; <=
;; @@
(cons 'he (cons 'said my-favorite-list))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>he</span>","value":"he"},{"type":"html","content":"<span class='clj-symbol'>said</span>","value":"said"},{"type":"html","content":"<span class='clj-symbol'>fe</span>","value":"fe"},{"type":"html","content":"<span class='clj-symbol'>fi</span>","value":"fi"},{"type":"html","content":"<span class='clj-symbol'>fo</span>","value":"fo"},{"type":"html","content":"<span class='clj-symbol'>fum</span>","value":"fum"}],"value":"(he said fe fi fo fum)"}
;; <=
;; @@
my-favorite-list
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>fe</span>","value":"fe"},{"type":"html","content":"<span class='clj-symbol'>fi</span>","value":"fi"},{"type":"html","content":"<span class='clj-symbol'>fo</span>","value":"fo"},{"type":"html","content":"<span class='clj-symbol'>fum</span>","value":"fum"}],"value":"(fe fi fo fum)"}
;; <=
;; @@
(first (rest (rest (first
'((deep
(in the (nested) structure)
lies
truth))))))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-symbol'>lies</span>","value":"lies"}
;; <=
;; @@
(inspect-tree '((deep
(in the (nested) structure)
lies
truth)))
; < window opens in the clojure.main application >
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>#object[javax.swing.JFrame 0x266ed37a "javax.swing.JFrame[frame1,0,23,400x600,layout=java.awt.BorderLayout,title=Clojure Inspector,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,22,400x578,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]"]</span>","value":"#object[javax.swing.JFrame 0x266ed37a \"javax.swing.JFrame[frame1,0,23,400x600,invalid,layout=java.awt.BorderLayout,title=Clojure Inspector,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,22,400x578,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]\"]"}
;; <=
;; @@
(second '(a b c d e))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-symbol'>b</span>","value":"b"}
;; <=
;; @@
(third '(a b c d e)) ;; nope
;; @@
;; @@
(nth '(a b c d e) 2)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-symbol'>c</span>","value":"c"}
;; <=
;; @@
(concat '(I like to eat) '(apples and bananas))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>I</span>","value":"I"},{"type":"html","content":"<span class='clj-symbol'>like</span>","value":"like"},{"type":"html","content":"<span class='clj-symbol'>to</span>","value":"to"},{"type":"html","content":"<span class='clj-symbol'>eat</span>","value":"eat"},{"type":"html","content":"<span class='clj-symbol'>apples</span>","value":"apples"},{"type":"html","content":"<span class='clj-symbol'>and</span>","value":"and"},{"type":"html","content":"<span class='clj-symbol'>bananas</span>","value":"bananas"}],"value":"(I like to eat apples and bananas)"}
;; <=
;; @@
(rand-nth '(a b c d e f g))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-symbol'>c</span>","value":"c"}
;; <=
;; @@
(flatten '(a (b (c d) (((e))) f (g))))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>b</span>","value":"b"},{"type":"html","content":"<span class='clj-symbol'>c</span>","value":"c"},{"type":"html","content":"<span class='clj-symbol'>d</span>","value":"d"},{"type":"html","content":"<span class='clj-symbol'>e</span>","value":"e"},{"type":"html","content":"<span class='clj-symbol'>f</span>","value":"f"},{"type":"html","content":"<span class='clj-symbol'>g</span>","value":"g"}],"value":"(a b c d e f g)"}
;; <=
;; @@
;; This returns a vector rather than a list:
(shuffle '(a b c d e f g))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-vector'>[</span>","close":"<span class='clj-vector'>]</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>c</span>","value":"c"},{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>g</span>","value":"g"},{"type":"html","content":"<span class='clj-symbol'>e</span>","value":"e"},{"type":"html","content":"<span class='clj-symbol'>d</span>","value":"d"},{"type":"html","content":"<span class='clj-symbol'>b</span>","value":"b"},{"type":"html","content":"<span class='clj-symbol'>f</span>","value":"f"}],"value":"[c a g e d b f]"}
;; <=
;; @@
;; We'll see more about vectors later, but both are "sequences" and many functions work
;; on either without change.
(count '(a b c d e f g))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>7</span>","value":"7"}
;; <=
;; @@
;; Problem Set 2:
;; - Create a complicated nested list using only cons, quoted symbols, and ().
;; - Pull out various parts of your list with nested calls to nth.
;; - Pull out random parts of your list with nested calls to rand-nth.
;; - Write an expression that produces a semi-random haiku.
;; @@
;; @@
(defn my-function
"Takes two arguments and returns a list with those arguments and
some other stuff."
[a b]
(list 'some a 'other b 'stuff))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/my-function</span>","value":"#'clojinc.core/my-function"}
;; <=
;; @@
(my-function 'nice 'stuffy)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>some</span>","value":"some"},{"type":"html","content":"<span class='clj-symbol'>nice</span>","value":"nice"},{"type":"html","content":"<span class='clj-symbol'>other</span>","value":"other"},{"type":"html","content":"<span class='clj-symbol'>stuffy</span>","value":"stuffy"},{"type":"html","content":"<span class='clj-symbol'>stuff</span>","value":"stuff"}],"value":"(some nice other stuffy stuff)"}
;; <=
;; @@
(defn random-element
"Returns a randomly selected element of the given sequence."
[s]
(nth s (rand-int (count s))))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/random-element</span>","value":"#'clojinc.core/random-element"}
;; <=
;; @@
(random-element '(a b c d e f g))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-symbol'>c</span>","value":"c"}
;; <=
;; @@
(= (+ 22 33 44) (* 33 3))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>true</span>","value":"true"}
;; <=
;; @@
(= (my-function 'nice 'stuffy) (my-function 'nice 'stuffy))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>true</span>","value":"true"}
;; <=
;; @@
(identical? (my-function 'nice 'stuffy) (my-function 'nice 'stuffy))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>false</span>","value":"false"}
;; <=
;; @@
(def x 23)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/x</span>","value":"#'clojinc.core/x"}
;; <=
;; @@
(def y 5)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/y</span>","value":"#'clojinc.core/y"}
;; <=
;; @@
(if (< x y)
(list x 'is 'smaller 'than y)
(list x 'is 'not 'smaller 'than y))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-long'>23</span>","value":"23"},{"type":"html","content":"<span class='clj-symbol'>is</span>","value":"is"},{"type":"html","content":"<span class='clj-symbol'>not</span>","value":"not"},{"type":"html","content":"<span class='clj-symbol'>smaller</span>","value":"smaller"},{"type":"html","content":"<span class='clj-symbol'>than</span>","value":"than"},{"type":"html","content":"<span class='clj-long'>5</span>","value":"5"}],"value":"(23 is not smaller than 5)"}
;; <=
;; @@
(cond
(< x y) (concat (list x) '(is smaller than) (list y))
(= x y) (concat (list x) '(is equal to) (list y))
:else (concat (list x) '(is greater than) (list y)))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-long'>23</span>","value":"23"},{"type":"html","content":"<span class='clj-symbol'>is</span>","value":"is"},{"type":"html","content":"<span class='clj-symbol'>greater</span>","value":"greater"},{"type":"html","content":"<span class='clj-symbol'>than</span>","value":"than"},{"type":"html","content":"<span class='clj-long'>5</span>","value":"5"}],"value":"(23 is greater than 5)"}
;; <=
;; @@
(defn add-20
"returns n + 20"
[n]
(+ n 20))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/add-20</span>","value":"#'clojinc.core/add-20"}
;; <=
;; @@
(add-20 15)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>35</span>","value":"35"}
;; <=
;; @@
(use 'clojure.repl) ;; need to do this to have access to the "doc" function below
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
;; @@
(doc add-20)
;; @@
;; ->
;;; -------------------------
;;; clojinc.core/add-20
;;; ([n])
;;; returns n + 20
;;;
;; <-
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
;; @@
;; Problem Set 3:
;; - Write functions that calculate, given reasonable numeric inputs, the values
;; of the aritmetic/geometric formulae that you provided for Problem Set 1.
;; - Write a function that takes a list of one-syllable words, a list of
;; two-syllable words, and a list of three-syllable words, and returns a haiku
;; constructed from the provided words.
;; @@
;; @@
(defn article
"Generates and returns an article as a symbol in a list."
[]
(list (random-element '(the a))))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/article</span>","value":"#'clojinc.core/article"}
;; <=
;; @@
(defn noun
"Generates and returns a noun as a symbol in a list."
[]
(list (random-element '(walrus steamboat pedestrian columnist pineapple contingency))))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/noun</span>","value":"#'clojinc.core/noun"}
;; <=
;; @@
(defn verb
"Generates and returns a verb as a symbol in a list."
[]
(list (random-element '(acquired apprehended loved liked loathed caressed confounded))))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/verb</span>","value":"#'clojinc.core/verb"}
;; <=
;; @@
(defn noun-phrase
"Generates and returns a noun-phrase as a list."
[]
(concat (article) (noun)))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/noun-phrase</span>","value":"#'clojinc.core/noun-phrase"}
;; <=
;; @@
(defn verb-phrase
"Generates and returns a verb-phrase as a list."
[]
(concat (verb) (noun-phrase)))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/verb-phrase</span>","value":"#'clojinc.core/verb-phrase"}
;; <=
;; @@
(defn sentence
"Generates and returns a sentence as a list."
[]
(concat (noun-phrase) (verb-phrase)))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/sentence</span>","value":"#'clojinc.core/sentence"}
;; <=
;; @@
(sentence)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>pedestrian</span>","value":"pedestrian"},{"type":"html","content":"<span class='clj-symbol'>loathed</span>","value":"loathed"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>contingency</span>","value":"contingency"}],"value":"(a pedestrian loathed the contingency)"}
;; <=
;; @@
;; again:
(sentence)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>contingency</span>","value":"contingency"},{"type":"html","content":"<span class='clj-symbol'>liked</span>","value":"liked"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>walrus</span>","value":"walrus"}],"value":"(the contingency liked the walrus)"}
;; <=
;; @@
;; again:
(sentence)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>steamboat</span>","value":"steamboat"},{"type":"html","content":"<span class='clj-symbol'>loved</span>","value":"loved"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>contingency</span>","value":"contingency"}],"value":"(the steamboat loved the contingency)"}
;; <=
;; @@
;; again:
(sentence)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>columnist</span>","value":"columnist"},{"type":"html","content":"<span class='clj-symbol'>confounded</span>","value":"confounded"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>columnist</span>","value":"columnist"}],"value":"(the columnist confounded the columnist)"}
;; <=
;; @@
;; again:
(sentence)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>walrus</span>","value":"walrus"},{"type":"html","content":"<span class='clj-symbol'>apprehended</span>","value":"apprehended"},{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>steamboat</span>","value":"steamboat"}],"value":"(a walrus apprehended a steamboat)"}
;; <=
;; @@
(noun-phrase)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>pedestrian</span>","value":"pedestrian"}],"value":"(a pedestrian)"}
;; <=
;; @@
(verb-phrase)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>acquired</span>","value":"acquired"},{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>pedestrian</span>","value":"pedestrian"}],"value":"(acquired a pedestrian)"}
;; <=
;; @@
(noun)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>columnist</span>","value":"columnist"}],"value":"(columnist)"}
;; <=
;; @@
(verb)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>liked</span>","value":"liked"}],"value":"(liked)"}
;; <=
;; @@
(let [my-sentence (sentence)]
(concat my-sentence (reverse my-sentence)))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>walrus</span>","value":"walrus"},{"type":"html","content":"<span class='clj-symbol'>liked</span>","value":"liked"},{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>columnist</span>","value":"columnist"},{"type":"html","content":"<span class='clj-symbol'>columnist</span>","value":"columnist"},{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>liked</span>","value":"liked"},{"type":"html","content":"<span class='clj-symbol'>walrus</span>","value":"walrus"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"}],"value":"(the walrus liked a columnist columnist a liked walrus the)"}
;; <=
;; @@
(let [my-sentence (sentence)
your-sentence (sentence)]
(concat '(I said that) my-sentence '(and you said that)
your-sentence '(to which I replied that)
my-sentence '(and you said finally that)
your-sentence))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-lazy-seq'>(</span>","close":"<span class='clj-lazy-seq'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>I</span>","value":"I"},{"type":"html","content":"<span class='clj-symbol'>said</span>","value":"said"},{"type":"html","content":"<span class='clj-symbol'>that</span>","value":"that"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>walrus</span>","value":"walrus"},{"type":"html","content":"<span class='clj-symbol'>apprehended</span>","value":"apprehended"},{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>walrus</span>","value":"walrus"},{"type":"html","content":"<span class='clj-symbol'>and</span>","value":"and"},{"type":"html","content":"<span class='clj-symbol'>you</span>","value":"you"},{"type":"html","content":"<span class='clj-symbol'>said</span>","value":"said"},{"type":"html","content":"<span class='clj-symbol'>that</span>","value":"that"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>pineapple</span>","value":"pineapple"},{"type":"html","content":"<span class='clj-symbol'>loathed</span>","value":"loathed"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>pedestrian</span>","value":"pedestrian"},{"type":"html","content":"<span class='clj-symbol'>to</span>","value":"to"},{"type":"html","content":"<span class='clj-symbol'>which</span>","value":"which"},{"type":"html","content":"<span class='clj-symbol'>I</span>","value":"I"},{"type":"html","content":"<span class='clj-symbol'>replied</span>","value":"replied"},{"type":"html","content":"<span class='clj-symbol'>that</span>","value":"that"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>walrus</span>","value":"walrus"},{"type":"html","content":"<span class='clj-symbol'>apprehended</span>","value":"apprehended"},{"type":"html","content":"<span class='clj-symbol'>a</span>","value":"a"},{"type":"html","content":"<span class='clj-symbol'>walrus</span>","value":"walrus"},{"type":"html","content":"<span class='clj-symbol'>and</span>","value":"and"},{"type":"html","content":"<span class='clj-symbol'>you</span>","value":"you"},{"type":"html","content":"<span class='clj-symbol'>said</span>","value":"said"},{"type":"html","content":"<span class='clj-symbol'>finally</span>","value":"finally"},{"type":"html","content":"<span class='clj-symbol'>that</span>","value":"that"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>pineapple</span>","value":"pineapple"},{"type":"html","content":"<span class='clj-symbol'>loathed</span>","value":"loathed"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>pedestrian</span>","value":"pedestrian"}],"value":"(I said that the walrus apprehended a walrus and you said that the pineapple loathed the pedestrian to which I replied that the walrus apprehended a walrus and you said finally that the pineapple loathed the pedestrian)"}
;; <=
;; @@
(let [x 0
x (+ x 1)
x (* x 100)
x (/ x 20)]
x)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-long'>5</span>","value":"5"}
;; <=
;; @@
(defn print-sentence
"Prints a sentence (symbols in a list) followed by a newline."
[s]
(doseq [word s] (print word) (print " "))
(println))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/print-sentence</span>","value":"#'clojinc.core/print-sentence"}
;; <=
;; @@
(print-sentence (sentence))
;; @@
;; ->
;;; a walrus loathed a contingency
;;;
;; <-
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
;; @@
;; again:
(print-sentence (sentence))
;; @@
;; ->
;;; a walrus acquired a pineapple
;;;
;; <-
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
;; @@
(do (cons 'this '(will happen but you will not see it))
(cons 'because '(all that gets returned from a "do" form))
(cons 'is '(the value of the last form within it)))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-list'>(</span>","close":"<span class='clj-list'>)</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>is</span>","value":"is"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>value</span>","value":"value"},{"type":"html","content":"<span class='clj-symbol'>of</span>","value":"of"},{"type":"html","content":"<span class='clj-symbol'>the</span>","value":"the"},{"type":"html","content":"<span class='clj-symbol'>last</span>","value":"last"},{"type":"html","content":"<span class='clj-symbol'>form</span>","value":"form"},{"type":"html","content":"<span class='clj-symbol'>within</span>","value":"within"},{"type":"html","content":"<span class='clj-symbol'>it</span>","value":"it"}],"value":"(is the value of the last form within it)"}
;; <=
;; @@
;; Problem Set 4:
;; - Generate random blues song lyrics. They should include repeated lines.
;; - Generate random melodies that include repeated lines.
;; @@
;; @@
;; this is a set:
#{:tree :mushroom :aardvark}
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:tree</span>","value":":tree"},{"type":"html","content":"<span class='clj-keyword'>:aardvark</span>","value":":aardvark"},{"type":"html","content":"<span class='clj-keyword'>:mushroom</span>","value":":mushroom"}],"value":"#{:tree :aardvark :mushroom}"}
;; <=
;; @@
(:tree #{:tree :mushroom :aardvark})
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-keyword'>:tree</span>","value":":tree"}
;; <=
;; @@
(:tree #{:free :mushroom :aardvark})
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
;; @@
(#{:tree :mushroom :aardvark} :tree)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-keyword'>:tree</span>","value":":tree"}
;; <=
;; @@
(contains? #{:free :mushroom :aardvark} :free)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>true</span>","value":"true"}
;; <=
;; @@
(some #{:free} #{:free :mushroom :aardvark})
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-keyword'>:free</span>","value":":free"}
;; <=
;; @@
(some even? #{9 3 4 1 11 8})
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>true</span>","value":"true"}
;; <=
;; @@
(use 'clojure.set)
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
;; @@
(select even? #{9 3 4 1 11 8})
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-long'>4</span>","value":"4"},{"type":"html","content":"<span class='clj-long'>8</span>","value":"8"}],"value":"#{4 8}"}
;; <=
;; @@
(conj #{:tree :mushroom :aardvark} :poppy)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:tree</span>","value":":tree"},{"type":"html","content":"<span class='clj-keyword'>:aardvark</span>","value":":aardvark"},{"type":"html","content":"<span class='clj-keyword'>:mushroom</span>","value":":mushroom"},{"type":"html","content":"<span class='clj-keyword'>:poppy</span>","value":":poppy"}],"value":"#{:tree :aardvark :mushroom :poppy}"}
;; <=
;; @@
(disj #{:tree :mushroom :aardvark} :tree)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:aardvark</span>","value":":aardvark"},{"type":"html","content":"<span class='clj-keyword'>:mushroom</span>","value":":mushroom"}],"value":"#{:aardvark :mushroom}"}
;; <=
;; @@
;; more ways of making sets:
(hash-set :tomato :cucumber :basil)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:cucumber</span>","value":":cucumber"},{"type":"html","content":"<span class='clj-keyword'>:basil</span>","value":":basil"},{"type":"html","content":"<span class='clj-keyword'>:tomato</span>","value":":tomato"}],"value":"#{:cucumber :basil :tomato}"}
;; <=
;; @@
(sorted-set :tomato :cucumber :basil)
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:basil</span>","value":":basil"},{"type":"html","content":"<span class='clj-keyword'>:cucumber</span>","value":":cucumber"},{"type":"html","content":"<span class='clj-keyword'>:tomato</span>","value":":tomato"}],"value":"#{:basil :cucumber :tomato}"}
;; <=
;; @@
(set '(apples bananas))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>apples</span>","value":"apples"},{"type":"html","content":"<span class='clj-symbol'>bananas</span>","value":"bananas"}],"value":"#{apples bananas}"}
;; <=
;; @@
(into #{} '(apples bananas))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-symbol'>apples</span>","value":"apples"},{"type":"html","content":"<span class='clj-symbol'>bananas</span>","value":"bananas"}],"value":"#{apples bananas}"}
;; <=
;; @@
(set (str 123))
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-char'>\\1</span>","value":"\\1"},{"type":"html","content":"<span class='clj-char'>\\2</span>","value":"\\2"},{"type":"html","content":"<span class='clj-char'>\\3</span>","value":"\\3"}],"value":"#{\\1 \\2 \\3}"}
;; <=
;; @@
(defn member?
"Returns true if item is in lst, false otherwise."
[item lst]
(if (some #{item} lst) true false))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'clojinc.core/member?</span>","value":"#'clojinc.core/member?"}
;; <=
;; @@
(member? \b (set "Eggbert"))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>true</span>","value":"true"}
;; <=
;; @@
(member? 1 '(2 3 1 5))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>true</span>","value":"true"}
;; <=
;; @@
(member? \1 (set (str 2315)))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>true</span>","value":"true"}
;; <=
;; @@
(member? \6 (set (str 2315)))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>false</span>","value":"false"}
;; <=
;; @@
(intersection #{:free :mushroom :aardvark}
#{:tree :mushroom :aardvark})
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:aardvark</span>","value":":aardvark"},{"type":"html","content":"<span class='clj-keyword'>:mushroom</span>","value":":mushroom"}],"value":"#{:aardvark :mushroom}"}
;; <=
;; @@
(union #{:free :mushroom :aardvark}
#{:tree :mushroom :aardvark})
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:tree</span>","value":":tree"},{"type":"html","content":"<span class='clj-keyword'>:aardvark</span>","value":":aardvark"},{"type":"html","content":"<span class='clj-keyword'>:free</span>","value":":free"},{"type":"html","content":"<span class='clj-keyword'>:mushroom</span>","value":":mushroom"}],"value":"#{:tree :aardvark :free :mushroom}"}
;; <=
;; @@
(difference #{:free :mushroom :aardvark}
#{:tree :mushroom :aardvark})
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-set'>#{</span>","close":"<span class='clj-set'>}</span>","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:free</span>","value":":free"}],"value":"#{:free}"}
;; <=
;; @@
(subset? #{:mushroom :aardvark}
#{:tree :mushroom :aardvark})
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>true</span>","value":"true"}
;; <=
;; @@
(superset? #{:tree :mushroom :aardvark}
#{:mushroom :aardvark})
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-unkown'>true</span>","value":"true"}
;; <=
;; @@
(let [my-sentence (sentence)]
(if (some #{'walrus} my-sentence)
(println 'pussycat)
(print-sentence my-sentence)))
;; @@
;; ->
;;; pussycat
;;;
;; <-
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=