Is it possible to check in macro if being compiled in Clojure or Clojurescript?

84 views
Skip to first unread message

Dominykas Mostauskis

unread,
Apr 19, 2015, 11:20:35 AM4/19/15
to clojur...@googlegroups.com
Is it possible to check in macro if being compiled in Clojure or Clojurescript?

When I'm writing a library for both Clojure and Clojurescript, I use the same file which I hardlink so that both compilers could access it. Ergo same code, which is very pleasant: until I have to use JVM or JS specific functionality. I'm looking for a painless way to expose different code to different compilers. cljx does the trick, but it's a leiningen plugin and I need a solution that would work on boot-clj.

Alan Dipert

unread,
Apr 19, 2015, 6:45:14 PM4/19/15
to clojur...@googlegroups.com
There is a cljx task for boot that you may consider: https://github.com/Deraen/boot-cljx

Alan

Daniel Compton

unread,
Apr 19, 2015, 9:35:54 PM4/19/15
to clojur...@googlegroups.com
This use case will be provided by Feature Expressions which are planned to come out in Clojure (JVM) 1.7 and presumably will come in a release of ClojureScript around the same time. You can find more details about this planned feature at http://dev.clojure.org/display/design/Feature+Expressions
On Mon, 20 Apr 2015 at 3:20 am Dominykas Mostauskis <dominykas....@gmail.com> wrote:
Is it possible to check in macro if being compiled in Clojure or Clojurescript?

When I'm writing a library for both Clojure and Clojurescript, I use the same file which I hardlink so that both compilers could access it. Ergo same code, which is very pleasant: until I have to use JVM or JS specific functionality. I'm looking for a painless way to expose different code to different compilers. cljx does the trick, but it's a leiningen plugin and I need a solution that would work on boot-clj.

--
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 clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Dominykas Mostauskis

unread,
Apr 20, 2015, 3:56:59 AM4/20/15
to clojur...@googlegroups.com
The 1.7.0-beta1 release has Reader Conditionals, and apparently the latest ClojureScript release as well. Wonderful, can't wait to try them out. This is the beta1 release announcement https://groups.google.com/forum/#!topic/clojure/7S127m8bLNQ

You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/zVHhgqGal6k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.

Chas Emerick

unread,
Apr 20, 2015, 1:55:53 PM4/20/15
to clojur...@googlegroups.com
When you're writing macros that should emit different code depending on
the language target, you can dispatch on the value of &env.

Although, your mention of using cljx makes me think that your scope is
broader than just macros…

- Chas
Reply all
Reply to author
Forward
0 new messages