This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-17
Channels
- # 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)
Hi, trying to upgrade an old project to clojurescript 1.9.946 and make use of the ability to import javascript modules but although it installs the proper libs when I run fig wheel (1.5.14 ) just running [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
I am not sure how to import javascript. I am using lein
if I ["jayso" :as jayson-rpc]
I get Assert failed: cljs.analyzer/foreign-dep? expected symbol got "jayson"
is there something I am not doing?Is this expected behaviour when overwriting 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!"
I'd expect if I refer a symbol, given the overwrite warning, that it would really overwrite the cljs.core function.@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-- map
?
Yeah, @hlolli you'd have to also define a +
macro. For example
;;;; 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
Then, in a REPL, you will see both being overwritten:
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
It is very intersting that your last expression
(`+ 1 2)
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 2
. For example
(`blah 34 77)
will return 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
(#'+ 1 2)
this would instead force it to go through the var, thus printing "Called!"
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.
Yes @noisesmith then +
is higher-order
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
We should not take that position
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?