This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-31
Channels
- # aleph (3)
- # aws (5)
- # beginners (65)
- # boot (17)
- # cljs-dev (112)
- # cljsrn (5)
- # clojure (146)
- # clojure-austin (3)
- # clojure-dusseldorf (3)
- # clojure-italy (18)
- # clojure-norway (13)
- # clojure-russia (84)
- # clojure-serbia (5)
- # clojure-spec (24)
- # clojure-uk (84)
- # clojurescript (204)
- # css (1)
- # cursive (21)
- # data-science (3)
- # datascript (21)
- # datomic (26)
- # emacs (5)
- # euroclojure (1)
- # hoplon (8)
- # jobs (7)
- # jobs-discuss (2)
- # keechma (35)
- # lumo (92)
- # mount (1)
- # nrepl (2)
- # numerical-computing (16)
- # off-topic (10)
- # om (58)
- # re-frame (13)
- # reagent (90)
- # remote-jobs (2)
- # ring-swagger (1)
- # spacemacs (9)
- # specter (6)
- # unrepl (17)
- # untangled (56)
- # yada (2)
1000 punti per la seguente:
(defn plus [x y] (+ x y))
(defn plus2 [y] (plus 2 y))
(plus2 5) ;; 7
;; plus2 is based on plus
(with-redefs [plus (constantly 0)] (plus2 5)) ;; 0
(defn plus3 [y] (inc (plus2 y)))
(plus3 5) ;; 8
;; plus3 is based on plus2 (which is based on plus)
(with-redefs [plus (constantly 0)] (plus3 5)) ;; 1
(def plus4 (fn [x] (+ 2 (plus2 x))))
(plus4 5) ;; 9
;; plus4 is based again on plus2 (which is based on plus)
(with-redefs [plus (constantly 0)] (plus4 5)) ;; 2
(def plus5 (fn [x] (plus x 5)))
(plus5 5) ;; 10
;; plus5 is based directly on plus with anon fn indirection
(with-redefs [plus (constantly 0)] (plus5 5)) ;; 0
(def plus6 (partial plus 6))
(plus6 5) ;; 11
;; plus6 is based on partial, which uses the anon fn indirection
(with-redefs [plus (constantly 0)] (plus6 5)) ;; 11
Perche' with-redefs smette di funzionare con partial?plus 2 to 3 essenzialmente non hanno grosse differenze, nonostante le varie indirezioni, plus
non viene mai catturato in un environment esterno al body di ciascuna definizione, quindi with-redefs ha effetto
plus6 e` l'unico diverso, ed e` sostanzialmente equivalente a (let [plus plus] (fn [x] (plus 6 x)))
i.e. in plus6
il linking e` a una variabile locale inizializzata a plus
che viene catturata, invece di un linking alla var plus
stessa
partial
e' essenzialmente (defn partial [f arg1] (fn [x] (f arg1 x)))
quindi mi stai dicendo che quando passo "f" come parametro in quel momento viene risolta f