Skip to content

Commit 40b6646

Browse files
Updates from todays ClojureBridge London workshop
1 parent bcd1b53 commit 40b6646

8 files changed

+104
-11
lines changed

SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
* [Named or anonymous functions](functions/named-or-anonymous-functions.md)
6464
* [Calling anonymous functions](functions/calling-anonymous-functions.md)
6565
* [Arguments to functions](functions/arguments-to-functions.md)
66-
* [Simplicity with Pure Functions](functions/pure-functions.md)
66+
* [Excercise: are we there yet?](functions/exercise-are-we-there-yet.md)
67+
* [Theory: Simplicity with Pure Functions](functions/pure-functions.md)
6768
* [Pure function examples](functions/pure-function-examples.md)
6869
* [Impure function examples](functions/impure-function-examples.md)
6970
* [Flow Control & Logic](flow-control-logic/index.md)

assignment/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Assignment with `def`
1+
# Assigning names to values
22

33
Rather than type the same values many times in our code, we can give them a name to refer to them. This is called assignment.
44

challenges-projects.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Congratulations, you have made it through the basics of Clojure
44

55
![Congratulations - minions](/images/congratulations-minions.gif)
66

7-
If you have time for more, then you can either work on some more challenges
7+
If you have time for more, then you can either work on some more challenges...
88

99
* [4Clojure challenges](http://www.4clojure.com/) - learn the many functions in Clojure and how they work
1010
* [Kata Challenges](kata-challenges/index.html) - test first approach to writing Clojure
1111

12-
If you have lots of time, then try one of the projects
12+
Or if you have lots of time, then try one of the **[projects](additional-projects/)**

collections/reading-values-from-vectors-sequentially.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ You can also combine these functions, so the results of one function call can be
1717
()
1818
```
1919

20+
<!--sec data-title="Reveal answer..." data-id="answer002" data-collapse=true ces-->
21+
22+
```clojure
23+
24+
(first (second ["Birthdays are" "full of" "presents" "that you" "always dreamd" "of having"]))
25+
26+
```
27+
28+
<!--endsec-->
29+
30+
2031
------------------------------------------
2132

2233
> #### Hint::

functions/name-smash.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ Take your name and the name of another student in the group and create a combine
3434
;;
3535
;; => ["Ada" "Lovelace" "Anne-Marie" "Imafidon"]
3636
```
37+
38+
In JavaScript the above gives a rather messy output of nested collections.
39+
40+
Mapping over the student collection gives cleaner return value
41+
42+
```clojure
43+
(map #(clojure.string/split % #" ") students)
44+
```
45+
46+
We can also flatten the result to make it look nicer
47+
48+
```clojure
49+
(flatten (map #(clojure.string/split % #" ") students))
50+
```
51+
3752
<!--endsec-->
3853

3954

simple-values/arithmetic.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ Look at these examples of Clojure code and their equivalent math expression:
2828
```eval-clojure
2929
(* 22/7 7)
3030
```
31+
32+
------------------------------------------
33+
34+
> #### Info::
35+
> Ratio types are not supported in the web browser REPL above, however, they will work in your editor
36+
>
37+
> Unfortunately JavaScript does not have anyway to support the Clojure ratio type.

simple-values/exercise-calculating-language-ages.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,51 @@ As there are two values the same, we could also calculate the total as follows
3737

3838

3939
> #### Note::Average age of programming languages
40-
> Calculate the average age of the 8 programming languages
40+
> Calculate the average age of the 10 programming languages
4141
```eval-clojure
4242
()
4343
```
4444

45+
------------------------------------------
46+
47+
> #### Hint::Counting values
48+
> You can simply divide the total age of all languages by 10.
49+
>
50+
> If you want to try something more advanced, then you can count the number of languages is to put them in a collection, eg.
51+
> `[10 27 26 21 22 22 45 34 59 60]`
52+
i>
53+
> The `count` function will tell you how many things are in a collection
54+
55+
56+
<!--sec data-title="Reveal answer..." data-id="answer002" data-collapse=true ces-->
57+
58+
We first add up the ages of all the language ages. Then we divide that total age with the number of languages
59+
60+
```clojure
61+
(/ (+ 10 27 26 21 22 22 45 34 59 60) 10)
62+
```
63+
64+
In a more advance clojure way we can also do
65+
66+
```clojure
67+
(/ (+ 10 27 26 21 22 22 45 34 59 60)
68+
(count [10 27 26 21 22 22 45 34 59 60]))
69+
```
70+
71+
<!--endsec-->
72+
73+
4574
------------------------------------------
4675

4776
> #### Note::Find the age of the youngest programming language
4877
```eval-clojure
4978
()
5079
```
80+
81+
<!--sec data-title="Reveal answer..." data-id="answer003" data-collapse=true ces-->
82+
83+
```clojure
84+
(first (sort [10 27 26 21 22 22 45 34 59 60]))
85+
```
86+
87+
<!--endsec-->

simple-values/strings.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ In the last example a backslash, `\`, is used to allow us to put special charact
1616

1717
## Working with strings
1818

19-
There are many functions that work with strings
19+
There are many functions that work with strings, especially in the `clojure.string` library
2020

21-
* [str](https://clojuredocs.org/clojure.core/str) - join values into a string
22-
* [split](https://clojuredocs.org/clojure.string/split) - split a string based on a pattern (regex)
23-
* [subs](https://clojuredocs.org/clojure.core/subs) - get part of a string
24-
* [replace](https://clojuredocs.org/clojure.string/replace) - replace part of the string based on a pattern (regex)
25-
* [includes?](https://clojuredocs.org/clojure.string/includes_q) - does a string include another string (true or false)
21+
* [clojure.string/str](https://clojuredocs.org/clojure.core/str) - join values into a string
22+
* [clojure.string/split](https://clojuredocs.org/clojure.string/split) - split a string based on a pattern (regex)
23+
* [clojure.string/subs](https://clojuredocs.org/clojure.core/subs) - get part of a string
24+
* [clojure.string/replace](https://clojuredocs.org/clojure.string/replace) - replace part of the string based on a pattern (regex)
25+
* [clojure.string/includes?](https://clojuredocs.org/clojure.string/includes_q) - does a string include another string (true or false)
2626

2727

2828
> #### Note::Create a String of favourite colours
@@ -31,6 +31,19 @@ There are many functions that work with strings
3131
()
3232
```
3333

34+
<!--sec data-title="Reveal answer..." data-id="answer001" data-collapse=true ces-->
35+
36+
```clojure
37+
;; Just simply use a string
38+
"I love purple"
39+
40+
;; Using a function you can create a string and join values to create a string
41+
(str "I love the colour " "purple")
42+
```
43+
44+
<!--endsec-->
45+
46+
3447
------------------------------------------
3548

3649
> #### Note::Does the string contain your favorite colour
@@ -41,6 +54,15 @@ There are many functions that work with strings
4154
()
4255
```
4356

57+
58+
<!--sec data-title="Reveal answer..." data-id="answer002" data-collapse=true ces-->
59+
60+
```clojure
61+
(clojure.string/includes? "Richard of York gave brown bread in vans" "brown")
62+
```
63+
<!--endsec-->
64+
65+
4466
------------------------------------------
4567

4668
> #### Hint::

0 commit comments

Comments
 (0)