This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-02
Channels
- # arachne (1)
- # bangalore-clj (3)
- # beginners (4)
- # boot (6)
- # cider (3)
- # cljs-dev (14)
- # cljsrn (2)
- # clojure (309)
- # clojure-ireland (1)
- # clojure-russia (7)
- # clojure-spec (10)
- # clojure-uk (5)
- # clojureremote (2)
- # clojurescript (68)
- # cursive (7)
- # emacs (7)
- # luminus (3)
- # lumo (21)
- # off-topic (14)
- # om (1)
- # onyx (53)
- # perun (3)
- # re-frame (4)
- # slack-help (14)
- # unrepl (56)
- # untangled (3)
I have something like
(ns current
#?(:cljs
;; import itself as a macro in cljs
(:require-macros
[current :refer [my-macro]]))
#?(:clj
(defmacro my-macro
[db-sym & body]
`(let [~db-sym 2]
(current/some-fct
(superv.async/go-try S
~@body))))))
But I keep getting warnings use of undeclared var current/some-fct
in the places where I use the macros
go-try
is also macro, but I guess it's implemented correctly: https://github.com/replikativ/superv.async/blob/master/src/superv/async.cljc#L133
@lsenta here is how I would do it, the macro is written in a clj file, shared between both clj and cljs and decides what code to generate based on cljs-env?
predicate, also uses CLJS-1507 to reduce reader conditionals noise:
[1] https://github.com/binaryage/env-config/blob/master/src/lib/env_config/impl/coercers.cljc#L4
[2] https://github.com/binaryage/env-config/blob/master/src/lib/env_config/impl/macros.cljs#L6
[3] https://github.com/binaryage/env-config/blob/master/src/lib/env_config/impl/macros.clj#L3
@U08E3BBST thanks for the advice, I'll try this approach next time. I think I need to work my way around "targeting directly the compiler phase".
How would you deal with the imports in the macros.clj
?
(if (cljs-env?)
(ns my.ns
(:require [cljs.core.async ...]))
(ns my.ns
(:require [clojure.core.async])))
you lost me here, I have a (ns something)
declaration at the top of my file, what's an alias? a (def alias 'my.long.namespace)
?
hmm although ... I'm confused by the current
.. single segment namespaces are usually treated as aliases
When the macro my.ns/my-macro
is expanded, the clj compiler writes the symbol (my.ns/some-fct ...)
but then the cljs compiler doesn't know the symbol, I have to add a regular (:require [my.ns])
for it to work.
I work in namespace a.a
.
my macro M
and the functions f
are in namespace a.b
In namespace a.a
, in cljs, if I require the macro M
and use it, it'll tell me the function are missing
which is messed up, if macro depends on n
namespaces then I need to import them all in every client namespaes?!
(ns a.b ;; cljc
#?(:cljs (:require-macro [a.b :refer [M]])))
(defn f [x]
...)
(defmacro M [k & body]
`(let [~k 12]
(f 12)
~@body)))
yes, if the namespace that provides a macro has a :require-macro
to itself that works
otherwise :require-macros
is leaky in that way yes, since that just requires the clojure file
Haha and I thought I was starting to understand the macro expansion phase, the fact that just require
works is mindblowing
FWIW a lot of problems go away if you only use :require-macros
in a namespace to require itself
Hi Guys, I would like to use `lein-cljsbuild β1.1.5ββ and newest clojurescript dependency. I got bug, but with clojurescript 1.7.170 and lein-cljsbuild 1.1.1 ok. What is the best option? (sorry for the beginner question, maybe do you have more experience and quick answer)
that looks like you are using a very new clojurescript
release but somehow get an old clojure-compiler
hmm might be something in lein-cljsbuild
.. the clojurescript 1.9.495
is not an official release yet
I have to develop in C++, but I wonder if there is any possibility to use Clojure to implement some of form of test for C++ code, treating the C++ code as data? I feel hopeful of the possibility after Watching the talk of Magic: Boom. Symbolic Assembly: Using Clojure to Meta-program Bytecode by @ra https://t.co/wzMBdKEvn6 Any pointer or comment is appreciated. I hope that the approach would increase productivity and rigor othe tests.
How do I run macroexpand
in cljs REPL for my macros? In Figwheel REPL I can evaluate (macroexpand '(int 5))
, but (macroexpand '(my-macro))
returns the from unchanged.
@dottedmag Be sure to define your macros in a Clojure source file and use require-macros
on its namespace name in the REPL.