
Reader Conditionals in Clojure - jballanc
http://dev.clojure.org/display/design/Reader+Conditionals
======
aaron-santos
As someone who uses cljx and leaves "lein cljx auto" and "lein cljsbuild auto"
running in the background, how is my workflow going to change when I switch to
reader conditionals?

~~~
schwap
If I understand right, you'll be able to eliminate the "lein cljx auto" and
instead the reader(s) will be responsible for using the correct platform-
specific snippet.

~~~
puredanger
Correct.

------
vosper
For someone who is very new to Clojure, but trying to learn, can someone
please explain what this is?

~~~
juvenn
There are (currently) three host implementations of clojure: Clojure(JVM),
ClojureCLR(.NET CLR), and ClojureScript(JavaScript). Supporting this reader
conditional can facilitate code reuse as much as possible.

~~~
jballanc
To expand on this a bit more: while all three implementations are "Clojure",
since Clojure is a hosted language (i.e. doesn't specify/implement its own VM)
and embraces this fact, there are subtle differences between the various
implementations. Some of these differences could be viewed as "bugs" and
should eventually go away (e.g. cannot use macros at runtime in CLJS), but
some are inherent to the platform (e.g. how do you convert a string to an
integer?).

Originally, if your code was simple enough and didn't touch any of the parts
that were different between the implementations, then you could simply run the
same code under Clojure, ClojureScript, and ClojureCLR. If it was even mildly
involved, though, you'd have to write separate implementations for each.

Then the CLJX project came along. It introduced the `#+clj` and `#+cljs` forms
that could be used to specify code that should only run under Clojure or
ClojureScript respectively. For Clojure v1.7.0, the goal is to implement
something similar in the core language. At first the plan was to simply adopt
the CLJX forms directly, but as of 1.7.0-alpha6 there is this new concept of a
conditional reader.

Ultimately, as a beginning Clojurist the impact to you should be small.
Eventually, if you are looking to write libraries to be used across both
Clojure and ClojureScript, this will be useful to reduce the amount of
duplication in your project. As you move towards the heights of advanced
Clojure usage, though, this turns out to be a very powerful concept that could
potentially be useful for a wide range of applications.

~~~
puredanger
Great answer.

------
smrtinsert
Did they change the syntax to full forms? Previously they looked like cljx
prefixes I thought. Looks much better imo.

~~~
puredanger
Yes, the conditional part is always an expression or a spliced list.

