-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Welcome to Chlorinejs wiki.
Chlorinejs is for those who want to keep Clojure syntax and habits in Javascript world.
-
Code readability over feature fullness
-
Unlike Clojurescript the full-featured official "clojure to javascript" solution working on Clojure data-structure, Chlorinejs is just a small subset language using syntax and a (limited) port of core library to deal with Javascript data-structure.
-
You don't have to convert between Clojure(script) datastructure and javascript's. Chlorinejs just works on the latter.
-
Chlorinejs is more a language for Clojure ecosystem than an independent one like Coffeescript or Livescript etc. You should learn Clojure properly to write good Chlorinejs pieces. Also, we recommend the choice of Clojurescript over Chlorinejs: only choose the Chlorinejs when the cost of Clojurescript really hurts you.
-
It's convenient to generate javascript from Clojure data-structure, just like Hiccup with HTML. (The Lisp's data ♥ code story, right?)
-
Chlorinejs is more a syntax transformer (but with macros!) than a smart compiler which understand your code. However, transpiling Chlorinejs is pretty fast.
-
Chlorinejs is like Scheme: it doesn't implement
namespace
feature. You can use nodejs/browserify's style:(require xyz)
to modularize. That may be inconvenient, but the benefit is that you need nojs/something
prefixes, and therequire
techniques may be used by existing javascript libraries you want to use. -
You define macros on the fly: no need to have all macros in other script files (as with Clojurescript).
-
Because Chlorinejs and javascript share many things in common, an automatic tool was made to help converting javascript to Chlorinejs.
- Clojure/Lisp symbol names (hence naming convention).
-
let
,loop/recur
,for
/doseq
,map
/reduce
are there. Forget C-like manualfor
loops. - Destructuring, multiple arity forms and
defmulti
/defmethod
make life easier. - Writing docstring is surely a good habit.
- The functional style: all forms should return something. Don't waste time writing code blocks that don't really help.
- Simple unit tests with
deftest
andis
(on top of mocha & qunit; easy to do live-coding with testem) - A port of core library means that you can use
=
to compare "vectors" (javascript arrays) and "maps" (javascript key-value objects);merge
,concat
etc work as you may expect. - Macros are easy to write. Included
cond
,if-let
,defn
etc are Chlorinejs macros. - A light-weight Atom implementation is available to separate identity and state.
- Try Chlorine in your browser (link) (source)
- Made some cool examples? Share them with the community just like those Showcases!
- Plan to learn Clojure if you haven't.
- Be creative, because Clojure is so powerful ;)
- If you want to [generate javascript in Clojure source files](Using Chlorine library), check out Chlorine library. However, in most cases you may want:
- Compile Chlorine to javascript files (or even Hiccup to HTML) independently using this Leiningen plugin.
- Check out the Showcases above for examples.
Still hungry of documentation? Get more details about how the compiler works or check the unit tests for use cases.