-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpart-1.html
More file actions
1203 lines (990 loc) · 23.6 KB
/
part-1.html
File metadata and controls
1203 lines (990 loc) · 23.6 KB
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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>(Clojure School)</title>
<meta name="author" content="(Likely)"/>
<link rel="stylesheet" href="./reveal.js/css/reveal.min.css"/>
<link rel="stylesheet" href="./reveal.js/css/theme/solarized.css" id="theme"/>
<link rel="stylesheet" href="css/zenburn.css"/>
<link rel="stylesheet" href="./reveal.js/css/print/pdf.css" type="text/css" media="print"/>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1>Clojure School</h1>
<h2>Likely</h2>
<h2><a href="mailto:"></a></h2>
<h2></h2></section>
<section>
<section id="sec-1" >
<h2>Welcome</h2>
</section>
</section>
<section>
<section id="sec-2" >
<h2>Introductions</h2>
<ul class="org-ul">
<li>Henry Garner (CTO, Likely)
</li>
<li>James Henderson (Senior Developer, Likely)
</li>
</ul>
<p>
Professionally using Clojure for 18 months
</p>
</section>
</section>
<section>
<section id="sec-3" >
<h2>Who are you?</h2>
<p>
… and what are you hoping to get out of these sessions?
</p>
</section>
</section>
<section>
<section id="sec-4" >
<h2>What we'll cover today</h2>
<ul class="org-ul">
<li>Getting up and running
</li>
<li>Language primitives
</li>
<li>Working with sequences
</li>
<li>Working with higher order functions
</li>
<li>Working with real data
</li>
<li>Moving beyond the REPL
</li>
</ul>
</section>
</section>
<section>
<section id="sec-5" >
<h2>Where will we get to in 4 weeks?</h2>
<ul class="org-ul">
<li>The ability to create your own non-trivial Clojure projects
</li>
</ul>
</section>
</section>
<section>
<section id="sec-6" >
<h2>Housekeeping</h2>
<ul class="org-ul">
<li>Experience of LISP?
</li>
<li>Other functional languages?
</li>
<li>What text editor?
</li>
<li>Who has Java?
</li>
<li>Who has leiningen?
</li>
</ul>
</section>
</section>
<section>
<section id="sec-7" >
<h2>Getting Set Up</h2>
<p>
First, you’ll need a Java Virtual Machine, or JVM, and its associated development tools, called the JDK. This is the software which runs a Clojure program. If you’re on Windows, install Oracle JDK 1.7. If you’re on OS X or Linux, you may already have a JDK installed. In a terminal, try:
</p>
<pre><code data-trim class="clojure">
which javac
</code></pre>
<p>
If you see something like
</p>
<pre><code data-trim class="clojure">
/usr/bin/javac
</code></pre>
<p>
Then you're good to go
</p>
<p>
Windows users: <a href="http://leiningen.org/#install">http://leiningen.org/#install</a>
</p>
</section>
</section>
<section>
<section id="sec-8" >
<h2>Leiningen</h2>
<div class="org-src-container">
<pre class="src src-bash">mkdir -p ~/bin
cd ~/bin
curl -O https://raw.github.com/technomancy/leiningen/stable/bin/lein
chmod a+x lein
</pre>
</div>
<div class="org-src-container">
<pre class="src src-bash">cd
lein new scratch
</pre>
</div>
<div class="org-src-container">
<pre class="src src-bash">export PATH="$PATH":~/bin
</pre>
</div>
</section>
</section>
<section>
<section id="sec-9" >
<h2>REPL</h2>
<div class="org-src-container">
<pre class="src src-bash">lein repl
</pre>
</div>
<p>
This is an interactive Clojure environment called a REPL, for “Read, Evaluate, Print Loop”. It’s going to read a program we enter, run that program, and print the results. REPLs give you quick feedback, so they’re a great way to explore a program interactively, run tests, and prototype new ideas.
</p>
</section>
</section>
<section>
<section id="sec-10" >
<h2>REPL</h2>
<p>
With most languages, you write the system from the outside.
</p>
<p>
With LISPs, you bring the system up and develop it from the inside.
</p>
</section>
</section>
<section>
<section id="sec-11" >
<h2>Jumping inside</h2>
<pre><code data-trim class="clojure">
user=> nil
nil
</code></pre>
<p>
nil is the most basic value in Clojure.
</p>
</section>
</section>
<section>
<section id="sec-12" >
<h2>Boolean values</h2>
<pre><code data-trim class="clojure">
user=> true
true
user=> false
false
</code></pre>
</section>
</section>
<section>
<section id="sec-13" >
<h2>Basic Types</h2>
<pre><code data-trim class="clojure">
0
-42
1.2e-5
1/3
"Hi there!"
\space
\E
:keywords
#"\d+"
</code></pre>
</section>
</section>
<section>
<section id="sec-14" >
<h2>Collection Types</h2>
<p>
Maps
</p>
<pre><code data-trim class="clojure">
{:a 1 :b 2}
</code></pre>
<p>
Sets
</p>
<pre><code data-trim class="clojure">
#{1 2 3}
</code></pre>
<p>
Vectors
</p>
<pre><code data-trim class="clojure">
[1 2 3]
</code></pre>
<p>
… that's it!
</p>
<p>
"It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures." —Alan Perlis
</p>
</section>
</section>
<section>
<section id="sec-15" >
<h2>Def</h2>
<pre><code data-trim class="clojure">
user=> (def x 3)
#'user/x
</code></pre>
<p>
We've defined a var in the 'user' namespace and can refer to it:
</p>
<pre><code data-trim class="clojure">
user=> x
3
</code></pre>
</section>
</section>
<section>
<section id="sec-16" >
<h2>Lists</h2>
<pre><code data-trim class="clojure">
user=> (1 2 3)
ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn
user/eval146 (NO_SOURCE_FILE:1)
</code></pre>
</section>
</section>
<section>
<section id="sec-17" >
<h2>Wha happen?</h2>
<p>
The REPL sees a list and treats it as a function invocation.
</p>
<p>
The first element in the list is always the function to be invoked, with any remaining elements passed as arguments.
</p>
</section>
</section>
<section>
<section id="sec-18" >
<h2>Function Invocation</h2>
<pre><code data-trim class="clojure">
user=> (inc 0)
1
user=> (inc x)
4
</code></pre>
</section>
</section>
<section>
<section id="sec-19" >
<h2>Nesting</h2>
<pre>
Increment
increment
the number
</pre>
<pre><code data-trim class="clojure">
user=> (inc (inc 0))
2
</code></pre>
</section>
</section>
<section>
<section id="sec-20" >
<h2>Evaluation</h2>
<p>
Every list starts with a verb. Parts of a list are evaluated from left to right. Innermost lists are evaluated before outer lists.
</p>
<pre><code data-trim class="clojure">
(+ 1 (- 5 2) (+ 3 4))
(+ 1 3 (+ 3 4))
(+ 1 3 7)
11
</code></pre>
</section>
</section>
<section>
<section id="sec-21" >
<h2>Control structures:</h2>
<pre><code data-trim class="clojure">
user=> (if (> 3 2) "Higher" "Lower")
"Higher"
user=> (when (< 3 2) "Lower")
nil
user=> (when (> 3 2)
(println "3 is greater than 2")
"Higher")
3 is greater than 2
"Higher"
</code></pre>
<p>
See also: `if-not` and `when-not`
</p>
</section>
</section>
<section>
<section id="sec-22" >
<h2>More conditionals</h2>
<pre><code data-trim class="clojure">
user=> (case (inc 3)
3 "Uh oh"
4 "Yep!"
"Not so sure...")
"Yep!"
user=> (cond
(= 4 (inc 2)) "(inc 2) is 4"
(= 4 (/ 8 2)) "Cond picks the first correct case"
(zero? (- (* 4 2) 8) "This is true, but we won't get here"
:otherwise "None of the above."
"Cond picks the first correct case"
</code></pre>
<p>
See also: condp
</p>
</section>
</section>
<section>
<section id="sec-23" >
<h2>Having fn yet?</h2>
<pre><code data-trim class="clojure">
user=> (fn [x] (+ x 1))
#<user$eval149$fn__150 user$eval149$fn__150@397d812b>
</code></pre>
<p>
We've created a function!
</p>
<pre><code data-trim class="clojure">
user=> (fn [x]
(if (even? x)
(inc x)
(dec x)))
#<user$eval149$fn__150 user$eval149$fn__150@397d812c>
</code></pre>
</section>
</section>
<section>
<section id="sec-24" >
<h2>Usage</h2>
<pre><code data-trim class="clojure">
user=> ((fn [x] (+ x 1)) 10)
11
</code></pre>
<p>
You probably won't see this in production code…
</p>
</section>
</section>
<section>
<section id="sec-25" >
<h2>Defn</h2>
<pre><code data-trim class="clojure">
user=> (def half
(fn [number]
(/ number 2)))
#'user/half
user=> (half 6)
3
</code></pre>
<p>
Creating a function and binding it to a var is so common that it has its own form: defn, short for def fn.
</p>
<pre><code data-trim class="clojure">
user=> (defn half [number]
(/ number 2))
#'user/half
</code></pre>
</section>
</section>
<section>
<section id="sec-26" >
<h2>Function Arity</h2>
<p>
Functions don’t have to take an argument. We’ve seen functions which take zero arguments, like (+).
</p>
<pre><code data-trim class="clojure">
user=> (defn half [] 1/2)
#'user/half
user=> (half)
1/2
</code></pre>
<p>
But if we try to use our earlier form with one argument, Clojure complains that the arity–the number of arguments to the function–is incorrect.
</p>
<pre><code data-trim class="clojure">
user=> (half 10)
ArityException Wrong number of args (1) passed to:
user$half clojure.lang.AFn.throwArity (AFn.java:437)
</code></pre>
</section>
</section>
<section>
<section id="sec-27" >
<h2>Multiple Arities</h2>
<p>
To handle multiple arities, functions have an alternate form. Instead of an argument vector and a body, one provides a series of lists, each of which starts with an argument vector, followed by the body.
</p>
<pre><code data-trim class="clojure">
user=> (defn half
([] 1/2)
([x] (/ x 2)))
#'user/half
user=> (half)
1/2
user=> (half 10)
5
</code></pre>
</section>
</section>
<section>
<section id="sec-28" >
<h2>Variable Arities</h2>
<p>
Some functions can take any number of arguments. For that, Clojure provides &, which slurps up all remaining arguments as a list:
</p>
<pre><code data-trim class="clojure">
user=> (defn vargs
[x y & more-args]
{:x x
:y y
:more more-args})
#'user/vargs
user=> (vargs 1)
ArityException Wrong number of args (1) passed to: user$vargs
clojure.lang.AFn.throwArity (AFn.java:437)
user=> (vargs 1 2)
{:x 1, :y 2, :more nil}
user=> (vargs 1 2 3 4 5)
{:x 1, :y 2, :more (3 4 5)}
</code></pre>
</section>
</section>
<section>
<section id="sec-29" >
<h2>Bindings</h2>
<p>
We know that symbols are names for things, and that when evaluated, Clojure replaces those symbols with their corresponding values.
</p>
<pre><code data-trim class="clojure">
user=> +
#<core$_PLUS_ clojure.core$_PLUS_@12992c>
</code></pre>
<p>
We can create names which are locally scoped.
</p>
<pre><code data-trim class="clojure">
user=> (let [cats 5]
(str "I have " cats " cats."))
"I have 5 cats."
</code></pre>
</section>
</section>
<section>
<section id="sec-30" >
<h2>Bindings are local</h2>
<p>
Let bindings apply only within the let expression itself. They also override any existing definitions for symbols at that point in the program. For instance, we can redefine addition to mean subtraction, for the duration of a let:
</p>
<pre><code data-trim class="clojure">
user=> (let [+ -]
(+ 2 3))
-1
</code></pre>
<p>
But that definition doesn’t apply outside the let:
</p>
<pre><code data-trim class="clojure">
user=> (+ 2 3)
5
</code></pre>
</section>
</section>
<section>
<section id="sec-31" >
<h2>Bindings can be composed</h2>
<p>
We can also provide multiple bindings. Since Clojure doesn’t care about spacing, alignment, or newlines, I’ll write this on multiple lines for clarity.
</p>
<pre><code data-trim class="clojure">
user=> (let [person "joseph"
num-cats 186]
(str person " has " num-cats " cats!"))
"joseph has 186 cats!"
</code></pre>
<p>
When multiple bindings are given, they are evaluated in order. Later bindings can use previous bindings.
</p>
<pre><code data-trim class="clojure">
user=> (let [cats 3
legs (* 4 cats)]
(str legs " legs all together"))
"12 legs all together"
</code></pre>
</section>
</section>
<section>
<section id="sec-32" >
<h2>Keywords as functions</h2>
<pre><code data-trim class="clojure">
user=> (def my-map {:a 1 :b 2})
#'user/my-map
user=> (:a my-map)
1
</code></pre>
</section>
</section>
<section>
<section id="sec-33" >
<h2>Destructuring</h2>
<pre><code data-trim class="clojure">
user=> (def my-map {:a 1 :b 2 :c [3 4 5]})
#'user/my-map
user=> (let [a (:a my-map)
b (:b my-map)]
(+ a b))
3
user=> (let [{a :a b :b} my-map]
(+ a b))
3
user=> (let [{:keys [a b]} my-map]
(+ a b))
3
</code></pre>
</section>
</section>
<section>
<section id="sec-34" >
<h2>Nested Destructuring</h2>
<pre><code data-trim class="clojure">
user=> (let [{:keys [c]} my-map
[c1 c2 c3] c]
(+ c1 c2 c3))
12
user=> (let [{[c1 c2 c3] :c} my-map]
(+ c1 c2 c3))
12
</code></pre>
</section>
</section>
<section>
<section id="sec-35" >
<h2>A brief tour of clojure.core</h2>
<p>
Working with maps:
</p>
<pre><code data-trim class="clojure">
user=> (def my-map {:a 1 :b 2})
#'user/my-map
user=> (assoc my-map :c 3)
{:a 1, :c 3, :b 2}
user=> (dissoc my-map :a)
{:b 2}
user=> my-map
{:a 1, :b 2}
</code></pre>
</section>
</section>
<section>
<section id="sec-36" >
<h2>A brief tour of clojure.core</h2>
<p>
Working with maps:
</p>
<pre><code data-trim class="clojure">
user=> (def my-map {:a 1
:b 2
:c {:d 4
:e 5}})
#'user/my-map
user=> (keys my-map)
(:a :c :b)
user=> (vals my-map)
(1 {:d 4, :e 5} 2)
user=> (assoc-in my-map [:c :f] 6)
{:a 1, :c {:f 6, :d 4, :e 5}, :b 2}
</code></pre>
</section>
</section>
<section>
<section id="sec-37" >
<h2>Vector functions</h2>
<pre><code data-trim class="clojure">
user=> (def my-coll [2 3 1 5 6 4 0])
#'user/my-coll
user=> (first my-coll)
2
user=> (second my-coll)
3
user=> (nth my-coll 4)
6
user=> (conj my-coll 7)
[2 3 1 5 6 4 0 7]
user=> my-coll
[2 3 1 5 6 4 0]
</code></pre>
</section>
</section>
<section>
<section id="sec-38" >
<h2>Vector functions</h2>
<pre><code data-trim class="clojure">
user=> (def my-coll [2 3 1 5 6 4 0])
#'user/my-coll
user=> (sort my-coll)
(0 1 2 3 4 5 6)
user=> (interpose -1 my-coll)
(2 -1 3 -1 1 -1 5 -1 6 -1 4 -1 0)
user=> (zipmap [:a :b :c :d :e :f] my-coll)
{:f 4, :e 6, :d 5, :c 1, :b 3, :a 2}
user=> (frequencies "Hello world!")
{\space 1, \! 1, \d 1, \e 1, \H 1, \l 3, \o 2, \r 1, \w 1}
</code></pre>
<p>
See also: concat, interleave, cons, last, butlast
</p>
</section>
</section>
<section>
<section id="sec-39" >
<h2>Sheer laziness</h2>
<p>
While Clojure is technically eager by default, most of the functions on collections operate lazily:
</p>
<pre><code data-trim class="clojure">
user=> (def my-coll [0 1 2 3 4 5 6])
#'user/my-coll
user=> (take 3 my-coll)
(0 1 2)
user=> (drop 2 my-coll)
(2 3 4 5 6)
user=> (partition 3 my-coll)
((0 1 2) (3 4 5))
user=> (partition-all 3 my-coll)
((0 1 2) (3 4 5) (6))
user=> (split-at 3 my-coll)
[(0 1 2) (3 4 5 6)]
user=> (range)
;; good luck with this one! (cancel with Ctrl-c)
user=> (range 5)
(0 1 2 3 4)
user=> (take 5 (range))
(0 1 2 3 4)
</code></pre>
</section>
</section>
<section>
<section id="sec-40" >
<h2>Higher order functions</h2>
<p>
Functions that accept or return functions
</p>
<pre><code data-trim class="clojure">
user=> (def names [{:forename "Henry" :surname "Garner"}
{:forename "James" :surname "Henderson"}])
#'user/names
user=> (defn full-name [{:keys [forename surname]}]
(str forename " " surname))
#'user/full-name
user=> (full-name (first names))
"Henry Garner"
user=> (map full-name names)
["Henry Garner" "James Henderson"]
</code></pre>
</section>
</section>
<section>
<section id="sec-41" >
<h2>Anonymous Functions</h2>
<p>
Used where you have a case for a single-use function that doesn't warrant a name.
</p>
<pre><code data-trim class="clojure">
user=> (def names [{:forename "Henry" :surname "Garner"}
{:forename "James" :surname "Henderson"}])
#'user/names
user=> (defn full-name [forename surname]
(str forename " " surname))
#'user/full-name
user=> (map (fn [x] (full-name (:forename x) (:surname x))) names)
;; Equivalent to
user=> (map #(full-name (:forename %) (:surname %)) names)
</code></pre>
</section>
</section>
<section>
<section id="sec-42" >
<h2>Anonymous function arities</h2>
<p>
You can refer to multiple args by %1, %2, …
</p>
<pre><code data-trim class="clojure">
(fn [x y] (+ x y))
;; Equivalent to
#(+ %1 %2)
</code></pre>
</section>
</section>
<section>
<section id="sec-43" >
<h2>Other higher-order functions</h2>
<p>
Higher order functions can make use of functions.
</p>
<pre><code data-trim class="clojure">
user=> (update-in {:name "Henry" :age 30} [:age] inc)
{:name "Henry" :age 31}
</code></pre>
</section>
</section>
<section>
<section id="sec-44" >
<h2>Sequence-Sequence higher order functions</h2>
<pre><code data-trim class="clojure">
user=> (map inc [1 2 3 4])
(2 3 4 5)
user=> (filter even? [1 2 3 4 5 6])
(2 4 6)
user=> (sort-by count ["bb" "aaa" "c"]
("c" "bb" "aaa")
user=> (sort-by first > [[1 2] [2 2] [3 3]])
([3 3] [2 2] [1 2])
</code></pre>
<p>
See also: mapcat, remove, partition-by
</p>
</section>
</section>
<section>
<section id="sec-45" >
<h2>Sequence in > Something else out</h2>
<pre><code data-trim class="clojure">
user=> (reduce + [1 2 3])
6
user=> (group-by even? [1 2 3 4])
{false [1 3], true [2 4]}
</code></pre>
</section>
</section>
<section>
<section id="sec-46" >
<h2>Namespaces</h2>
<p>
In the REPL we get a 'user' namespace. In larger projects we like to split our code out into more namespaces.
</p>
<p>
We can refer to symbols in other namespaces.
</p>
<pre><code data-trim class="clojure">
(ns some.namespace
(:require [other.namespace :as blah]))
</code></pre>
</section>
</section>
<section>
<section id="sec-47" >
<h2>Leiningen's project.clj</h2>
<pre><code data-trim class="clojure">
(defproject weather "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[clj-http "0.7.7"]])
</code></pre>
</section>
</section>
<section>
<section id="sec-48" >
<h2>Your code goes here</h2>
<p>
src/weather/core.clj
</p>
<p>
Open up that file and remove the template function.
</p>
</section>
</section>
<section>
<section id="sec-49" >
<h2>Add dependencies</h2>
<pre><code data-trim class="clojure">
(ns weather.core
(:require [clj-http.client :as http]))
</code></pre>
</section>
</section>
<section>
<section id="sec-50" >
<h2>Let's use some real data</h2>