Syntax Flashcards
How to sum two values?
(+ 2 2)
; 4
How to thread something and return nil when some function returns nil?
(some-> …)
How to declare a function for test something?
(deftest test-something
(testing “describe the test”
…))
How to require a namespace and use functions without the prefix?
Using :require [… :refer :all]
What is uberjar?
Create a stand-alone .jar to be executed.
How to execute a .jar file?
java -jar /path/to/file.jar
How to start REPL with lein?
lein repl
What are the main control flow in clojure?
if, do, when
The best way to get a value of a map with keyword?
(:name person)
What are de diference between list an vectores?
When you add something to the list it goes to the front, instead of going to the end in vectors.
What are the main advantage to use a set?
Sets store unique values, if you try to add a value that already exists, it will be ignored.
What is high order functions?
Functions that returns or receive a function
How to declare a function with multiple-arity?
(defn x-chop ([name chop-type] (str "I " chop-type " chop " name "! Take that!")) ([name] (x-chop name "karate")))
How to get the rest of arguments received in a function?
(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 to destructure a vector passed as argument?
;; 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”