Cause its all a sham, my dear pumpkin ;) https://clojurescript.org/about/differences#_macros
AFAIK, the macros are actually compiled as Clojure, so the conditional readers don't do what you think they do. Here is what I do in a case close to yours: (defn- cljs-env? "Take the &env from a macro, and tell whether we are expanding into cljs. Source: http://v.gd/rmKNdf" [env] (boolean (:ns env))) (defmacro message-type? [message type] (let [is (if (cljs-env? &env) 'cljs.test/is 'clojure.test/is)] `(~is (= ~type (get-in ~message [:body :type]))))) On Friday, 27 October 2017 00:06:45 UTC+3, Vitalie Spinu wrote: > > Hi, > > I am having hard time writing a macro in cljc which uses core.async/go > macro. > > Minimal project that illustrates the problem is here > <https://github.com/vspinu/clj-problems/tree/cljs-undefined>. In a > nutshell: > > core.clj: > > (ns cljproj.core > (:require > #?(:clj [clojure.core.async :refer [go >! <!]] > :cljs [cljs.core.async :as a :refer [>! <!]])) > #?(:cljs > (:require-macros > [cljproj.core] > [cljs.core.async.macros :as am :refer [go]]))) > > (defmacro tt [ch] > `(go (println (<! ~ch)))) > > > > > dep.clj: > > (ns cljproj.dep > (:require > [clojure.core.async :as a] > [cljproj.core :refer [tt]])) > > (defn pp [] > (tt (a/chan))) > > > > > When dep.clj is compiled (./build.sh) the following warning shows: > > WARNING: Use of undeclared Var cljs.core.async/go at line 7 src/cljproj/ > dep.cljc > > At the repl (./node_repl.sh) the above `pp` function throws `Cannot read > property 'call' of undefined` because `tt` expands into > > > cljproj.dep> (macroexpand-1 '(tt (a/chan))) > (clojure.core.async/go (clojure.core/println (clojure.core.async/<! > (a/chan)))) > > So, that reference to `go` expands into `clojure.core.async/go` instead > of the `cljs.core.async.macro/go`. > > Is this a bug or I am doing something wrong here? What is the canonical > way to require async in cljc files? > > Many thanks! > > Vitalie > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
