-
compute
1+1
-
call the function
get
with arguments"ciao"
and1
-
compute
(3+4/5)*6
-
define a vector with the elements
1
,"hello"
andtrue
-
define a vector that contains the keywords
:diff
and:merge
-
define a map with the key
1
is associated with the value"hello"
and the key:key
with the value[13 7]
-
use
def
to define a variablemy-map
that refers to the map{1 2}
. Use theassoc
function to add a new key and value tomy-map
. What does theassoc
call return? What is the value ofmy-map
after the call? -
use
conj
to add a value to a vector -
use the function
get
to get the second element from a vector -
use the function
get
to get the value of a key from a map -
get the value of a key from a map using the map itself as a function
-
get the value of a key from a map using a keyword as a function
-
use the function
get-in
to return the value:treasure
from the value:{:description "cave" :crossroads [{:contents :monster} nil {:contents [:trinket :treasure]}]}
-
use
defn
to define a function hello that works like this:(hello) ==> "hello!"
-
define a function
double
that works like this:(double 5) ==> 10
,(double 1) ==> 2
-
add a docstring to the function
double
. Then show it using(doc double)
. -
challenge! implement a
factorial
function using recursion.
-
use the
let
structure to define a local variableb
with the value"bork"
. Then use thestr
function to combine twob
s into"borkbork"
. -
define a function
small?
that returnstrue
for numbers under 100 -
define a function
message!
that has three cases:(message! :boink) ==> "Boink!" (message! :pig) ==> "oink" (message! :ping) ==> "pong"
-
reimplement
message!
using theif
structure -
reimplement
message!
using thecond
structure -
reimplement
message!
using thecase
structure -
challenge! use the
loop
structure to add1
to an empty vector until it has 10 elements. Note:loop
can be hard. Don't get stuck on this exercise!
-
increment all the numbers in the vector
[4 7 9 10]
by one. Use themap
funktiota. Hint: the functioninc
-
do the same as in the previous exercise, but leave only the even results in the vector. Use the functions
filter
andeven?
-
use the
for
structure to go through this vector of maps:[{:id 1 :value 7.0} {:id 2 :value 3.0} {:id 7 :value 1.1}]
and return a sequence of the
:value
s:(7.0 3.0 1.1)
-
Use the function
update-in
to change 3 into 4 in the value below:{:shops [:shop-1] :customers [{:id "Pekka" :account {:balance 3}}]}
-
challenge! use the
reduce
function to combine a vector of maps like this:(combine [{:a 1 :b 2} {:c 3} {:d 4 :e 5}]) ==> {:a 1 :b 2 :c 3 :d 4 :e 5}