Skip to content

How to make a clojure library self host compatible

Yehonathan Sharvit edited this page Oct 27, 2016 · 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.

From Clojure to ClojureScript

  • rename files from .clj to .cljc
  • use #?(:cljs ... :clj) when a different code is needed for clojure and clojurescript
  • move the macros into a .clj file

From ClojureScript to Self-host compatible

Planck

  • 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.

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

Coding the port

Reader conditionals

In self-host, reader conditionals always branch to :cljs.

Data Types and protocols

Clojure and Clojurescript data types and protocols are very different

Macros

Macro code must be put in a separate file - .clj or .cljc

Debugging

It's hard!

Clone this wiki locally