Files
honore-beaugrand/Cours 4.ipynb
T
2018-09-09 17:04:03 -04:00

5.7 KiB

Class numero quatro

Some small remarks

Note on immutability

In [8]:
(def lst [1 2 3 4 5 6 7 8])

(defn times-2 [n]
    (* 2 n))

(def lst-2 (map times-2 lst))
Out [8]:
#'user/lst-2

Note on lazyness

In [6]:
(def all-numbers (range))
(def all-even-numbers (map times-2 all-numbers))
(take 10 all-even-numbers)
Out [6]:
(0 2 4 6 8 10 12 14 16 18)

Note on comments

In [36]:
(def foo 2) ;; this is a comment.  We call it a "line comment"

(comment (println "This is what we call a block comment, rarely used"))


#_(println "This is another type of block comment, more often used.  (used by david nolen)")

Hyperfiddle

This is the coolest thing ever! http://www.hyperfiddle.net/

if and when

Sometime, we only want to do "stuff" when something happen. This is moment to use if and when

In [14]:
(defn print-odd-or-even [n]
    (if (odd? n)
        (println n " is odd")
        (println n " is even")))
Out [14]:
#'user/print-odd-or-even
In [32]:
(require '[clojupyter.misc.display :as display]) ;; https://github.com/clojupyter/clojupyter
In [38]:
(display/html "<h3>We can very easely print stuff from code</h3>") 
Out [38]:

We can very easely print stuff from code

In [43]:
(defn html-h1 [title])
Out [43]:
#'user/html-h1

James Reeves made a fantastic, database, library for html called hiccup.

In [42]:
(display/hiccup-html [:h3 "hiccup is much better"])
Out [42]:

hiccup is much better

In [45]:
(defn hiccup-h1 [title])
Out [45]:
#'user/hiccup-h1

Dodgeball data

In [ ]:
(def dodgeball-data
    [{:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}
     {:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}
     {:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}
     {:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}])