This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # adventofcode (96)
- # beginners (49)
- # boot (3)
- # cider (3)
- # cljs-dev (3)
- # clojure (112)
- # clojure-austin (2)
- # clojure-greece (35)
- # clojure-india (2)
- # clojure-sanfrancisco (1)
- # clojure-spec (1)
- # clojure-sweden (1)
- # clojurescript (27)
- # cursive (4)
- # data-science (1)
- # datomic (33)
- # defnpodcast (1)
- # duct (2)
- # editors (1)
- # emacs (4)
- # events (2)
- # figwheel (4)
- # fulcro (4)
- # hoplon (29)
- # instaparse (1)
- # jobs (1)
- # keechma (4)
- # lein-figwheel (2)
- # om (1)
- # parinfer (4)
- # perun (23)
- # reitit (11)
- # shadow-cljs (8)
- # specter (23)
- # uncomplicate (16)
[jayson :as jayson-rpc] gives me
base.js:1357 Uncaught Error: Undefined nameToPath for jayson at visitNode (base.js:1357) at visitNode (base.js:1355) at Object.goog.writeScripts_ (base.js:1369) at Object.goog.require (base.js:706) at (index):2
["jayso" :as jayson-rpc]I get
is there something I am not doing?
Assert failed: cljs.analyzer/foreign-dep? expected symbol got "jayson"
Is this expected behaviour when overwriting cljs.core function
I'd expect if I refer a symbol, given the overwrite warning, that it would really overwrite the cljs.core function.
;;;;;;; file a ;;;;;; (ns file.a) (defn + [& vals] (prn "Called!") (apply cljs.core/+ vals)) ;;;;;;;;;; file b;;;;; (ns file.b (:require [file.a :refer [+]])) (+ 1 2 ) ;; Doesn't print "Called!" (file.a/+ 1 2) ;; Prints "Called!" (`+ 1 2) ;; Prints "Called!"
@hlolli I have a hunch that this might be b/c
+ is also a macro which is picked up here. but just a guess. So: Does the same happen with --e.g--
Yeah, @hlolli you'd have to also define a
+ macro. For example
Then, in a REPL, you will see both being overwritten:
;;;; a.clj ;;; (ns file.a) (defmacro + [a b] `(do (println "macro called!") (+ ~a ~b))) ;;; a.cljs ;;; (ns file.a (:require-macros file.a)) (defn + [& vals] (prn "Called!") (apply cljs.core/+ vals)) ;;; b.cljs ;;; (ns file.b (:require [file.a :refer [+]])) (+ 1 2 ) ;; Prints "macro called!" (file.a/+ 1 2) ;; Prints "macro called!" (`+ 1 2) ;; Doesn't print anything but returns 2
It is very intersting that your last expression
cljs.user=> (require 'file.b) WARNING: + already refers to: #'clojure.core/+ in namespace: file.a, being replaced by: #'file.a/+ WARNING: + already refers to: cljs.core/+ being replaced by: file.a/+ at line 3 /Users/mfikes/Desktop/src/file/a.cljs macro called! macro called! nil
prints "Called" for you. This shouldn't happen—I'd recheck your original test. This is essentially applying a symbol to a value which will look it up and if failing, should return the not-found value
(`+ 1 2)
2. For example
(`blah 34 77)
77, no matter what else is defined.
ah yes @mfikes yes you're right, I got confused, because when the plus fails I get
"[object Object][object Object]" because I'm attempting to use the plus sign to do more than it should. But with the syntax quote, I just get the return value of the expression, which is the return value I was expecting from this operation, and that confused me, the print statement is not called.
I wish I could edit my jira ticket, to remove this part, and the formatting 🙂 But as you say, rewriting the macro is maybe a must @mfikes do you see this as a bug, or is the macro replacement just something that I'd have to do?
FWIW, if you change that to
this would instead force it to go through the var, thus printing
(#'+ 1 2)
I don't see it as a bug, in that things are working as intended. Perhaps it warrants a warning. Hrm.
I assume if you replaced
(+ x y) with
(apply + [x y]) that would also force the non-macro version
One thing that could happen is that you could overwrite some core function, and then later if a core macro were introduced for performance reasons, it would be a breaking change. That would not be bueno.
having one symbol bound to a macro and also a function seems like it was asking for trouble in the first place?
unless we take the principled position that one should never replace things in cljs.core / clojure.core I guess
Perhaps the symbol resolution mechanics in CloureScript could be revised so that it doesn't greedily do macroexpansion in that case. Hmm.
I think those core macros are only there for performance, and their existence is intended to be transparent.
isn't this problem essentially a cljs.analyzer problem with the namespace? If a symbol is rewritten, in my case with a function, then for that namespace all pointers to the + as macro should be removed?
@hlolli One workaround is to
(:refer-clojure :exclude [+]) in every file you either define or refer a non-core version of