Home
Flashcards
Preview
Clojure Keywords
Home
Get App
Take Quiz
Create
first
return first element in list or vector
rest
return all elements except the first
cons
change in a list
Returns a new seq where x is the first element and seq is the rest.
(cons 1 '(2 3 4 5 6))
;;=> (1 2 3 4 5 6)
conj
;; notice that conjoining to a vector is done at the end
(conj [1 2 3] 4)
;;=> [1 2 3 4]
;; notice conjoining to a list is done at the beginning
(conj '(1 2 3) 4)
;;=> (4 1 2 3)
list
'( )
map
{ }
vector
[ ]
peek - list
return the first element in a list
pop - list
removes first element
peek - vector
returns last element
pop - vector
removes last element
big difference between keywords with list and vector
lists work with the first elements
vectors work with the last elements
subvec
return the end element but not the start
(subvec ("a" "big" "red" "apple") 1 3)
returns=> "red" "apple"
vector only
set
remove repeating
returns distinct elements
subvec with only one number
returns elements after the start to the end
user=> (subvec [12 3 4 5 6 7] 2)
[4 5 6 7]
#( )
set
dissoc
map
dissoc[iate].
removes the given element returning a new map
keys vs. vals
10 "Ten"
key = 10
val = "Ten"
%1 %2 %3
use for multiple elements to be called
assoc
assoc[iate]
changes the selected element value
user=> (assoc [1 2 3] 0 10)
[10 2 3]
false?
Returns true if x is the value false, false otherwise.
nil?
Returns true if x is nil, false otherwise.
filter
(filter even? (range 10))
;;=> (0 2 4 6 8)
range
(range 5)
= 0 1 2 3 4
drop
Returns a lazy sequence of all but the first n items in coll.
(drop 2 [1 2 3 4])
;;=> (3 4)
take
Returns a lazy sequence of the first n items in coll, or all items if there are fewer than n.
(take 3 '(1 2 3 4 5 6))
;;=> (1 2 3)
repeat
user=> (take 5 (repeat "x"))
("x" "x" "x" "x" "x")
identity
keyword
(fn[n] n)
for
(def digits (seq [1 2 3]))
(for [x1 digits x2 digits] (* x1 x2))
;;=> (1 2 3 2 4 6 3 6 9)
compliment
opposite
symbol
'a
"a"
let
bind to value
comp
composition
can bind a word to 2 or more values
last element gets applied first
((comp str +) 8 8 8) ;;=> "24"
dec
-1
destructuring
pull out 1 or more values from a structure
{ }
map
atom
Creates and returns an Atom with an initial value of x
user=> (def my-atom (atom 0))
swap!
swaps the value of atom to be
(def counter (atom 0))
(swap! counter inc)
;;=> 1
immutable
unchanging over time or unable to be changed.
do
used to evaluate multiple expressions in order
=> (do
(println "LOG
: Computing...")
(+ 1 1))
LOG
: Computing...
2
compare-and-set!
sets the value of atom to newval if and only if the
current value of the atom is identical to oldval
partition
stops if partition cannot be filled in contrast to the range
(partition 4 (range 22))
;;=> ((0 1 2 3) (4 5 6 7) (8 9 10 11) (12 13 14 15) (16 17 18 19))
partition-all
Returns a lazy sequence of lists like partition, but may include partitions with fewer than n items at the end.
(partition 4 (range 22));;=> ((0 1 2 3) (4 5 6 7) (8 9 10 11) (12 13 14 15) (16 17 18 19) (20 21))
Author
djon
ID
293035
Card Set
Clojure Keywords
Description
clojure keywords
Updated
2015-01-16T02:20:16Z
Show Answers
Home
Flashcards
Preview