Skip to content

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.

From Clojure to ClojureScript

  • rename non macro files from .clj to .cljc
  • use reader conditionals when a different code is needed for clojure and clojurescript
  • move the macros code into a .clj or .cljc 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 - 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.

Data Types and protocols

Clojure and Clojurescript data types and protocols are very different

Debugging

It's hard!

Clone this wiki locally