Created
August 9, 2019 13:33
-
-
Save jafingerhut/63a17a7b9562237954cf4be62bb9fae4 to your computer and use it in GitHub Desktop.
Does with-redefs work for functions in cljs.core, e.g. like vector in this example?
This file contains 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 characters
;; Command to start ClojureScript REPL: | |
;; clj -Sdeps "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.520\"}}}" -m cljs.main --repl-env node | |
(defn wrapme [wrapped-fn a another-fn] | |
(fn [& args] | |
(println "called wrapped fn") | |
(let [ret (apply wrapped-fn args)] | |
(apply another-fn a ret args) | |
ret))) | |
(defn f1 [x y & args] | |
(println "f1 x=" x "y=" y "args=" (vec args))) | |
(def my-vector vector) | |
(defn other-f4 [p q r] | |
(println "f4 here") | |
(my-vector p q r)) | |
;; this causes other-f4 to call wrapme'd version of my-vector | |
;; printing these msgs: | |
;; f4 here | |
;; called wrapped fn | |
;; f1 x= foo ... | |
(with-redefs [my-vector (wrapme my-vector "foo" f1)] | |
(other-f4 13 17 19)) | |
(defn f4 [p q r] | |
(println "f4 here") | |
(vector p q r)) | |
;; This only prints: | |
;; f4 here | |
;; so it must not be calling the wrapped version of the function, nor f1 | |
(with-redefs [vector (wrapme vector "foo" f1)] | |
(f4 13 17 19)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment