-
-
Notifications
You must be signed in to change notification settings - Fork 149
How to make a clojure library self host compatible
Viktor Magyari edited this page Jan 31, 2017
·
11 revisions
In order to make a clojure library self host compatible, you need first to port it to cljc and then make it self-host compatible.
- rename non macro files from
.cljto.cljc - use reader conditionals when a different code is needed for clojure and clojurescript
- move the macros code into a
.cljor.cljcfile
- install planck
- move to the main folder of your library
- Launch planck with the correct classpath:
planck -c`lein classpath`- require the namespaces of your libray
- fix the bugs
- test again
Once you are done push the code to github and test online with KLIPSE.
- Open the KLIPSE REPL with
external-data-libs=[<your raw github root>]e.g.http://app.klipse.tech/?external-libs=[https://raw.githubusercontent.com/viebel/math.combinatorics/master/src/main/clojure/] - require the namespaces of your libray
- fix the bugs and re-push
- test again
In self-host, reader conditionals always branch to :cljs - even for macro files.
As a result, the following will not compile (it will get into an infinite loop to be precise):
;; foo/bar.cljc
(ns foo.bar
#?(:cljs (:require-macros [foo.bar])))
;; macro definitions
See https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure#namespaces / Implicit macro loading.
Clojure and Clojurescript data types and protocols are very different
It's hard!