Syntax Flashcards

1
Q

How to sum two values?

A

(+ 2 2)

; 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to thread something and return nil when some function returns nil?

A

(some-> …)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to declare a function for test something?

A

(deftest test-something
(testing “describe the test”
…))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to require a namespace and use functions without the prefix?

A

Using :require [… :refer :all]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is uberjar?

A

Create a stand-alone .jar to be executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to execute a .jar file?

A

java -jar /path/to/file.jar

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to start REPL with lein?

A

lein repl

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the main control flow in clojure?

A

if, do, when

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The best way to get a value of a map with keyword?

A

(:name person)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are de diference between list an vectores?

A

When you add something to the list it goes to the front, instead of going to the end in vectors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the main advantage to use a set?

A

Sets store unique values, if you try to add a value that already exists, it will be ignored.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is high order functions?

A

Functions that returns or receive a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to declare a function with multiple-arity?

A
(defn x-chop
  ([name chop-type]
     (str "I " chop-type " chop " name "! Take that!"))
  ([name]
     (x-chop name "karate")))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to get the rest of arguments received in a function?

A

(defn favorite-things
[name & things]
(str “Hi, “ name “, here are my favorite things: “
(clojure.string/join “, “ things)))

(favorite-things “Doreen” “gum” “shoes” “kara-te”)
; => “Hi, Doreen, here are my favorite things: gum, shoes, kara-te”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to destructure a vector passed as argument?

A

;; Return the first element of a collection
(defn my-first
[[first-thing]] ; Notice that first-thing is within a vector
first-thing)

(my-first [“oven” “bike” “war-axe”])
; => “oven”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to destructure a map and mainten the orginal value?

A

(defn receive-treasure-location
[{:keys [lat lng] :as treasure-location}]
(println (str “Treasure lat: “ lat))
(println (str “Treasure lng: “ lng))

;; One would assume that this would put in new coordinates for your ship
(steer-ship! treasure-location))

17
Q

How to declare anonymous functions?

A
(fn [x] (+ x 1))
#(+ % 1)
18
Q

What is closure?

A

Functions that returns another functions.