Thanks Thomas for the detailed answer! It definitively helped me.

In my scenario I actually had a ClojureScript file but my issue was how to
reference the Clojure file defining the defmethods. As this file doesn't
define any macro I didn't realize I could reference it using require-macros
anyway. Best option seems to be #3.

e.g.

some Clojure file defining defmethods:

(ns my-defmethods)

(defmethod assert-expr :always-fail [msg form]
  ...)

some ClojureScript file defining tests:

(ns my-tests
      ... ; clojurescript.test imports
       (:require-macros [my-defmethods]))

It works perfectly!

> The gist is that ClojureScript must be told to load a Clojure file, it
can't figure this out by itself.
Actually it looks like any .clj file containing a macro will be loaded
anyway. Now it is definitively a more fragile option especially regarding
loading order.

Cheers,
Julien

2014-12-07 14:25 GMT-03:00 Thomas Heller <[email protected]>:

> Hey,
>
> I'm honestly not quite sure what you are asking but maybe I can shed some
> light on the way the ClojureScript compiler handles Clojure code (ie.
> macros).
>
> Whenever the cljs.analyzer reads a (ns ...) form and encounters anything
> that mentions a macro, like
>
> (:require-macros [some.ns :refer (my-macro)])
> (:require [some.ns :include-macros true])
> (:require [some.ns :refer-macros (my-macro)])
>
> It will 'clojure.core/require the corresponding Clojure Namespace
> ('some.ns in my example), normal Clojure loading rules apply so everything
> is loaded (if there is a defmethod it will be eval'd).
>
> Now, my guess is that you want to load a Clojure file without a
> corresponding ClojureScript file? Say, a bunch of (defmethod assert-expr
> ...)?
>
> Option #1: Create an empty ClojureScript (ns ...) with the same name as
> the Clojure Namespace and (:require [some.ns :include-macros true]).
>
> Option #2: Create an empty ClojureScript (ns ... (:require-macros
> [my.clojure-ns])) and require it as normal in CLJS
>
> Option #3: Just (:require-macros [my.clojure-ns])
>
> Option #4: Could be achieved with shadow-build but I wouldn't recommend it
> since it would only work with YOUR build configuration.
>
> The gist is that ClojureScript must be told to load a Clojure file, it
> can't figure this out by itself.
>
> (ns my-app.my-tests
>   (:require-macros [my-app.test-utils])
>   (:require [clojurescript.test]))
>
> Note that you don't actually have to define any macros, the 'ns will be
> required nonetheless. Its basically just a way to tell the cljs compiler
> that there is some clojure code we want loaded.
>
> HTH,
> /thomas
>
> --
> Note that posts from new members are moderated - please be patient with
> your first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to