Skip to content

Commit c5558fb

Browse files
intro: update clojure in 15 mins answers and formatting
1 parent 6ce9040 commit c5558fb

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

docs/introduction/clojure-in-15-minutes.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A quick tour of the Clojure syntax and common functions, which is so terse you can read through this page in around 15 minutes and have a basic understanding of the language.
44

55
!!! HINT "Try the code out in the REPL"
6-
[Start a Clojure REPL]() or use a [Clojure aware editor](/clojure/clojure-editors/) connected to a REPL and experiment with these code examples.
6+
[:fontawesome-solid-book-open: Start a Clojure REPL](/clojure/clojure-cli/repl/) or use a [:fontawesome-solid-book-open: Clojure aware editor](/clojure/clojure-editors/) connected to a REPL and experiment with these code examples.
77

88
Using the REPL provides instant feedback on each expression as they are evaluated, greatly increasing your understanding.
99

@@ -14,7 +14,7 @@ A quick tour of the Clojure syntax and common functions, which is so terse you c
1414

1515
`#_` comment reader macro to comment out the next form
1616

17-
`(comment )` form to comment all the containing forms, useful to [:fontawesome-solid-book-open: separate experimental and established code](https://practical.li/clojure/introduction/repl-workflow/#rich-comment-blocks-living-documentation) in a namespace.
17+
`(comment ,,,)` form to comment all the containing forms, useful to [:fontawesome-solid-book-open: separate experimental and established code](/clojure/introduction/repl-workflow/#rich-comment-blocks-living-documentation) in a namespace.
1818

1919

2020
## Clojure expressions
@@ -25,12 +25,12 @@ Clojure evaluates the first element in an expression as a function call. Additi
2525

2626
!!! EXAMPLE "Function call with value and expression as arguments"
2727
```clojure
28-
(+ 2007 (* 1 16))
28+
(+ 2007 (* 1 16))
2929
```
3030

3131
!!! EXAMPLE "Functions can be passed as an argument"
3232
```clojure
33-
(map inc (range 0 99))
33+
(map inc (range 0 99))
3434
```
3535

3636
## Organising Clojure
@@ -51,7 +51,7 @@ A company name or community repository name is often used making the namespace u
5151

5252
!!! EXAMPLE "Define a longer namespace"
5353
```clojure title="src/com/company/product/component_name.clj"
54-
(ns com.company.product.component-name) ;;
54+
(ns com.company.product.component-name)
5555
```
5656

5757
??? WARNING "Namespaces use dash, directory and file names use underscore"
@@ -92,15 +92,15 @@ Nesting forms defined a very precise calculation
9292
```clojure
9393
(* 1 2 (- 24 (* 7 3)))
9494
```
95-
96-
`6` is returned as the value. Nested expressions are typically read inside out. `(* 7 3)` is `21`, giving `(- 24 21)` expression resulting in `3`. Finally the expression becomes `(* 1 2 3)`, resulting in a value of `6`
95+
96+
`6` is returned as the value. Nested expressions are typically read inside out. `(* 7 3)` is `21`, giving `(- 24 21)` expression resulting in `3`. Finally the expression becomes `(* 1 2 3)`, resulting in a value of `6`
9797

9898

9999
Maintain precision for calculations using a Ratio type in Clojure
100100

101101
!!! EXAMPLE "Clojure Ratio value"
102102
```clojure
103-
(/ 27 7)
103+
(/ 27 7) ; => 27/7
104104
```
105105

106106
`22/7` is returned as the value, rather than a floating point value (double) which may loose some precision due to rounding.
@@ -145,7 +145,7 @@ A predicate is a function that returns a boolean `true` or `false` value and by
145145
All other values are consider true.
146146

147147

148-
[:fontawesome-solid-book-open: Clojure Standard Library Predicate Functions](https://practical.li/clojure/reference/standard-library/predicate-functions/){.md-button}
148+
[:fontawesome-solid-book-open: Clojure Standard Library Predicate Functions](https://practical.li/clojure/reference/standard-library/predicate-functions/){.md-button}
149149

150150

151151
## Collections & Sequences
@@ -182,10 +182,11 @@ Sequences are an interface for logical lists, which can be lazy. "Lazy" means th
182182

183183
A lazy sequence enables the use of large or even an infinite series, like so:
184184

185-
```clojure
186-
(range) ; => (0 1 2 3 4 ...) - an infinite series
187-
(take 4 (range)) ; (0 1 2 3) - lazyily evaluate range and stop when enough values are taken
188-
```
185+
!!! EXAMPLE "Lazy sequences"
186+
```clojure
187+
(range) ; => (0 1 2 3 4 ...) - an infinite series
188+
(take 4 (range)) ; (0 1 2 3) - lazyily evaluate range and stop when enough values are taken
189+
```
189190

190191
Use cons to add an item to the beginning of a list or vector
191192

@@ -237,10 +238,10 @@ Equivalent of `(conj (conj (conj [] 3) 2) 1)`
237238
Use `fn` to create new functions that defines some behaviour. `fn` is referred to as an anonymous fuction as it has no external name to be referenced by and must be called within a list form.
238239

239240
```clojure
240-
(fn hello [] "Hello World")
241+
(fn hello [] "Hello World")
241242
```
242243

243-
Wrap a `(fn ,,,)` form in parens to call it and return the result.
244+
Wrap a `(fn ,,,)` form in parens to call it and return the result.
244245

245246
!!! EXAMPLE "Call an anonymous function"
246247
```clojure
@@ -254,16 +255,16 @@ Normally the anonymous function is used inline with other code
254255
(map (fn [x] (* x 2)) [1 2 3 4 [1 2 3 4 5]5])
255256
```
256257

257-
Make the anonymous function reusable by binding it to a shared name (`var`) using `def`.
258+
Make the anonymous function reusable by binding it to a shared name (`var`) using `def`.
258259

259260
The `var` name bound to the function can now be called anywhere in the namespace.
260261

261262
> As `def` creates a `var` (variable) name, the developer can changed the expression the name is bound to and re-evaluated to use the changed behaviour.
262263
263264
!!! EXAMPLE "Bind a name to the anonymous function"
264265
```clojure
265-
(def hello-world
266-
(fn hello [] "Hello World"))
266+
(def hello-world
267+
(fn hello [] "Hello World"))
267268
```
268269

269270
!!! EXAMPLE "Evaluate annonymous function by evaluating its name"
@@ -282,7 +283,7 @@ It is more common to use the `defn` macro to define a function. This is the sam
282283
```clojure
283284
(defn hello-world
284285
"I am a humble doc-string, please describe the function purpose"
285-
[]
286+
[]
286287
"Hello World")
287288
```
288289

@@ -296,7 +297,7 @@ It is more common to use the `defn` macro to define a function. This is the sam
296297
(hello-world)
297298
```
298299

299-
The `[]` vector is used to define the argument names for the function. There can be zero or more arguments.
300+
The `[]` vector is used to define the argument names for the function. There can be zero or more arguments.
300301

301302
!!! EXAMPLE "Call function with arguments"
302303
```clojure
@@ -574,7 +575,7 @@ Vectors and Lists are java classes too!
574575

575576
!!! INFO "Type hints"
576577
Type hints can be used to avoid reflection look-ups where performace critical issues have been identified. Type hints are not required in general.
577-
[Clojure Type Hints](https://clojure.org/reference/java_interop#typehints){target=_blank .md-button}
578+
[Clojure Type Hints](https://clojure.org/reference/java_interop#typehints){target=_blank .md-button}
578579

579580
## Java Interop
580581

0 commit comments

Comments
 (0)