Last active
August 29, 2016 00:31
-
-
Save cairesr/565ae17ae98bc06f1a3b314cb7ea96fa to your computer and use it in GitHub Desktop.
Revisions
-
cairesr revised this gist
Aug 29, 2016 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -139,4 +139,15 @@ Binds values to new symbols. Values can be expressions. It's a way of saying: "c (if (> iteration 9) (println "Got it, exiting") (recur (inc iteration)))) ; => Iteration 0 ; => Iteration 1 ; => Iteration 2 ; => Iteration 3 ; => Iteration 4 ; => Iteration 5 ; => Iteration 6 ; => Iteration 7 ; => Iteration 8 ; => Iteration 9 ; => Got it, exiting ``` -
cairesr renamed this gist
Aug 29, 2016 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -129,4 +129,14 @@ Binds values to new symbols. Values can be expressions. It's a way of saying: "c (def musics ["Phosphene Dream" "Pink Cigarrete" "Beyond the Realms of Death"]) (let [[first-music & the-list] musics] [first-music the-list]) => ["Phosphene Dream" ("Pink Cigarrete" "Beyond the Realms of Death")] ``` ### Loop ```clojure (loop [iteration 0] (println "Iteration " iteration) (if (> iteration 9) (println "Got it, exiting") (recur (inc iteration)))) ``` -
cairesr revised this gist
Aug 29, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -117,7 +117,7 @@ Sets are collections of unique elements. ### Let Binds values to new symbols. Values can be expressions. It's a way of saying: "create local names for existent values" ```clojure (def musics ["Phosphene Dream" "Pink Cigarrete" "Beyond the Realms of Death"]) -
cairesr revised this gist
Aug 29, 2016 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -116,8 +116,17 @@ Sets are collections of unique elements. > Notice that using get to test whether a set contains nil will always return nil, which is confusing. - Daniel Higginbotham (Clojure for the Brave and True) ### Let Binds values to new symbols. Values can be expressions. ```clojure (def musics ["Phosphene Dream" "Pink Cigarrete" "Beyond the Realms of Death"]) (let [couple (take 2 musics)] (print couple)) => (Phosphene Dream Pink Cigarrete) ``` ```clojure (def musics ["Phosphene Dream" "Pink Cigarrete" "Beyond the Realms of Death"]) (let [[first-music & the-list] musics] [first-music the-list]) => ["Phosphene Dream" ("Pink Cigarrete" "Beyond the Realms of Death")] ``` -
cairesr revised this gist
Aug 29, 2016 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -113,4 +113,11 @@ Sets are collections of unique elements. (get #{nil 123} nil) => nil (get #{1 2 3} 85) = nil ``` > Notice that using get to test whether a set contains nil will always return nil, which is confusing. - Daniel Higginbotham (Clojure for the Brave and True) ### Let ```clojure (def musics ["Phosphene Dream" "Pink Cigarrete" "Beyond the Realms of Death"]) (let [couple (take 2 musics)] (print couple)) => (Phosphene Dream Pink Cigarrete) ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,7 +73,8 @@ ``` ### vectors x lists For a nubie (as I am), the rule of thumb is: > use a `list` when you need to add `elements` at the beginning of a `sequence`. Or when you write a `macro`. Otherwise, use `vector`. - Daniel Higginbotham (Clojure for the Brave and True) ### set Sets are collections of unique elements. -
cairesr renamed this gist
Aug 1, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -112,4 +112,4 @@ Sets are collections of unique elements. (get #{nil 123} nil) => nil (get #{1 2 3} 85) = nil ``` > Notice that using get to test whether a set contains nil will always return nil, which is confusing. - Daniel Higginbotham (Clojure for the Brave and True) -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -104,4 +104,12 @@ Sets are collections of unique elements. (nil #{:a :2}) => throws IllegalArgumentException - Can't call nil ("word" #{"word" 1}) => throws ClassCastException - String cannot be cast to clojure.lang.IFn (1 #{"word" 1}) => throws ClassCastException - java.lang.Long cannot be cast to clojure.lang.IFn ``` ```clojure (get #{1 "a"} "a") => "a" (get #{1 1/4} 1/4) => 1/4 (get #{nil 123} nil) => nil (get #{1 2 3} 85) = nil ``` > Notice that using get to test whether a set contains nil will always return nil, which is confusing. contains? may be the better option when you’re testing specifically for set membership. - Daniel Higginbotham (Clojure for the Brave and True) -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -102,4 +102,6 @@ Sets are collections of unique elements. ```clojure (:a #{:a :2}) => :a finds the element using the keyword as the function and the set as the argument for that function (nil #{:a :2}) => throws IllegalArgumentException - Can't call nil ("word" #{"word" 1}) => throws ClassCastException - String cannot be cast to clojure.lang.IFn (1 #{"word" 1}) => throws ClassCastException - java.lang.Long cannot be cast to clojure.lang.IFn ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -97,4 +97,9 @@ Sets are collections of unique elements. ```clojure (contains? #{1 2} 1) => true (contains? #{nil "a"} nil) => true ``` ```clojure (:a #{:a :2}) => :a finds the element using the keyword as the function and the set as the argument for that function (nil #{:a :2}) => throws IllegalArgumentException - Can't call nil ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 9 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -75,20 +75,26 @@ ### vectors x lists > For a nubie (as I am), the rule of thumb is: use a `list` when you need to add `elements` at the beginning of a `sequence`. Or when you write a `macro`. Otherwise, use `vector`. - Daniel Higginbotham (Clojure for the Brave and True) ### set Sets are collections of unique elements. ```clojure #{"awesome" 1 :simbolo 1/4} => #{"awesome" 1 :simbolo 1/4} creates a hash-set literal (hash-set "awesome 1 :simbolo 1/4) => #{"awesome" 1 :simbolo 1/4} creates a hash-set ``` ```clojure (hash-set 1 1 2 2) => #{1 2} (hash-set [1 1 2 2]) => #{[1 1 2 2]} (hash-set [1 1 2 2] [1 1 2 2]) => #{[1 1 2 2]} #{1 1 2 2} => throws IllegalArgumentException (Duplicate key) ``` ```clojure (set [1 1 2 2]) => #{1 2} creates a set with the given vector ``` ```clojure (contains? #{1 2} 1) => true (contains? #{nil "a"} nil) => true ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -82,7 +82,13 @@ Sets are collections of unique elements. #{"awesome" 1 :simbolo 1/4} => #{"awesome" 1 :simbolo 1/4} creates a set literal (hash-set "awesome 1 :simbolo 1/4) => #{"awesome" 1 :simbolo 1/4} creates a set ``` ```clojure (hash-set 1 1 2 2) => #{1 2} #{1 1 2 2} => throws IllegalArgumentException (Duplicate key) ``` ``` (contains? #{1 2} 1) => true (contains? #{nil "a"} nil) => true ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -83,5 +83,6 @@ Sets are collections of unique elements. (hash-set "awesome 1 :simbolo 1/4) => #{"awesome" 1 :simbolo 1/4} creates a set ``` ```clojure (hash-set 1 1 2 2) => #{1 2} #{1 1 2 2} => throws IllegalArgumentException (Duplicate key) ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -81,4 +81,7 @@ Sets are collections of unique elements. ```clojure #{"awesome" 1 :simbolo 1/4} => #{"awesome" 1 :simbolo 1/4} creates a set literal (hash-set "awesome 1 :simbolo 1/4) => #{"awesome" 1 :simbolo 1/4} creates a set ``` ```clojure #{1 1 2 2} => #{1 2} ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -75,5 +75,10 @@ ### vectors x lists > For a nubie (as I am), the rule of thumb is: use a `list` when you need to add `elements` at the beginning of a `sequence`. Or when you write a `macro`. Otherwise, use `vector`. - Daniel Higginbotham (Clojure for the Brave and True) ### hash-set Sets are collections of unique elements. ```clojure #{"awesome" 1 :simbolo 1/4} => #{"awesome" 1 :simbolo 1/4} creates a set literal (hash-set "awesome 1 :simbolo 1/4) => #{"awesome" 1 :simbolo 1/4} creates a set ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,8 +73,7 @@ ``` ### vectors x lists > For a nubie (as I am), the rule of thumb is: use a `list` when you need to add `elements` at the beginning of a `sequence`. Or when you write a `macro`. Otherwise, use `vector`. - Daniel Higginbotham (Clojure for the Brave and True) ### sets Sets are collections of unique elements. -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,8 +73,8 @@ ``` ### vectors x lists > For a nubie (as I am), the rule of thumb is: use a `list` when you need to add `elements` at the beginning of a `sequence`. Or when you write a `macro`. Otherwise, use `vector`. > - Daniel Higginbotham (Clojure for the Brave and True) ### sets Sets are collections of unique elements. -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,7 +73,8 @@ ``` ### vectors x lists > For a nubie (as I am), the rule of thumb is: use a `list` when you need to add `elements` at the beginning of a `sequence`. Or when you write a `macro`. Otherwise, use `vector`. > Daniel Higginbotham - Clojure for the Brave and True ### sets Sets are collections of unique elements. -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,7 +73,7 @@ ``` ### vectors x lists > For a nubie (as I am), the rule of thumb is: use a `list` when you need to add `elements` at the beginning of a `sequence`. Or when you write a `macro`. Otherwise, use `vector`. ### sets > Sets are collections of unique elements. -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -76,4 +76,4 @@ For a nubie (as I am), the rule of thumb is: use a `list` when you need to add `elements` at the beginning of a `sequence`. Or when you write a `macro`. Otherwise, use `vector`. ### sets > Sets are collections of unique elements. -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,4 +73,7 @@ ``` ### vectors x lists For a nubie (as I am), the rule of thumb is: use a `list` when you need to add `elements` at the beginning of a `sequence`. Or when you write a `macro`. Otherwise, use `vector`. ### sets #### Sets are collections of unique elements. -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -70,4 +70,7 @@ ``` ```clojure (conj '(1 2 3) 4 5 6) ;; => (6 5 4 1 2 3) (elements are added at the beginning of the list) ``` ### vectors x lists For a nubie (as I am), the rule of thumb is: use a `list` when you need to add `elements` at the beginning of a `sequence`. Or when you write a `macro`. Otherwise, use `vector`. -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,9 +42,9 @@ ### vector ```clojure [1 2 3] ;; => [1 2 3] creates a vector literal (vector 1 2 3) ;; [1 2 3] creates a vector through the vector function (vector [1 {a: "opa" b: 1/2} "da string" 23/39]) ;; => [1 {a: "opa" b: 1/2} "da string" 23/39] a vector accepts any type ``` ```clojure -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -61,7 +61,8 @@ ### lists ```clojure '(1 2 3 4) ;; => (1 2 3 4) creates a list literal (list 1 :simbolo {:name "Cartman" :age 7} 1/2) ;; => (1 :simbolo {:name "Cartman" :age 7} 1/2) creates a list ``` ```clojure (nth '(1 2 3 4) 0) ;; => 1 -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,7 +56,7 @@ ``` ```clojure (conj [1 2 3] 4 5 6) ;; => [1 2 3 4 5 6] (elements are added at the end of the vector) ``` ### lists @@ -66,4 +66,7 @@ ```clojure (nth '(1 2 3 4) 0) ;; => 1 (nth '(1 2 3 4) 4) ;; => throws IndexOutOfBoundException ``` ```clojure (conj '(1 2 3) 4 5 6) ;; => (6 5 4 1 2 3) (elements are added at the beginning of the list) ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,4 +62,8 @@ ### lists ```clojure '(1 2 3 4) ;; creates a list literal ``` ```clojure (nth '(1 2 3 4) 0) ;; => 1 (nth '(1 2 3 4) 4) ;; => throws IndexOutOfBoundException ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,10 +46,20 @@ (vector 1 2 3) ;; creates a vector through the vector function (vector [1 {a: "opa" b: 1/2} "da string" 23/39]) ;; a vector can accept elements of any type ``` ```clojure (get [25 35 300] 0) ;; => 1 (0th element) (get [25 35 300] 2) ;; => 300 (2nd element) (get [25 35 300] 3) ;; => nil (there's no 3rd element) ([25 35 300] 0) ;; => 1 (0th element) ([25 35 300] 3) ;; => throws IndexOutOfBoundsException (different behaviour from `(get [25 35 300] 3)`) ``` ```clojure (conj [1 2 3] 4 5 6) ;; => [1 2 3 4 5 6] ``` ### lists ```clojure '(1 2 3 4) ;; creates a list literal ``` -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,6 +44,7 @@ ```clojure [1 2 3] ;; creates a vector literal (vector 1 2 3) ;; creates a vector through the vector function (vector [1 {a: "opa" b: 1/2} "da string" 23/39]) ;; a vector can accept elements of any type ``` ```clojure (get [25 35 300] 0) ;; => 1 (0th element) -
cairesr revised this gist
Aug 1, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,5 +50,5 @@ (get [25 35 300] 2) ;; => 300 (2nd element) (get [25 35 300] 3) ;; => nil (there's no 3rd element) ([25 35 300] 0) ;; => 1 (0th element) ([25 35 300] 3) ;; => throws IndexOutOfBoundsException (different behaviour from `(get [25 35 300] 3)`) ```
NewerOlder