Self-Hosted ClojureScript入門



Self-Hosted ClojureScript入門

0 0


selfhosted-cljs-slide


On Github ykomatsu / selfhosted-cljs-slide

Self-Hosted ClojureScript入門

2016.05.21 Yoshito Komatsu

What is ClojureScript?

ClojureScript is a compiler for Clojure that targets JavaScript. It is designed to emit JavaScript code which is compatible with the advanced compilation mode of the Google Closure optimizing compiler.

--- clojure/clojurescript: Clojure to JS compiler https://github.com/clojure/clojurescript

ClojureScriptコンパイラーはClojure/Java VMで動く

ClojureScriptコンパイラーをClojureScriptコンパイラーでコンパイルしたい

The Beginning of Self-Hosted ClojureScript

self-hosting (A compiler) can compile its own code

Self-Hosted ClojureScript is also known as:

  • Bootstrapped ClojureScript
  • ClojureScript-in-ClojureScript

kanaka/clojurescript: Clojure to JS compiler (patched to allow compiling of compiler to ClojureScript) https://github.com/kanaka/clojurescript

swannodette/cljs-bootstrap: ClojureScript compiling ClojureScript https://github.com/swannodette/cljs-bootstrap

Self-Hosted ClojureScript

2015.07.29

ClojureScript can compile itself.

--- David Nolen, ClojureScript Next

想定される使用例1

  • Shipping dev tools that don't require a JVM dependency.
  • Low-latency scripting, making use of JavaScript engines' inherent fast startup in interpreted mode. Currently bootstrapped ClojureScript REPLs are 20-30% faster to start up than Clojure and tens of times faster than the standard JVM based ClojureScript REPLs.
  • Live updates to deployed codebases. (Ship code that can be compiled in target environment and dynamically incorporated in app. Mobile app updates, etc.)

--- Bootstrapped ClojureScript FAQ

想定される使用例2

  • Web pages that provide dynamic online tutorials or showcase ClojureScript libraries.
  • REPLs on mobile devices, without requiring network access to a compiler backend.
  • Diagnostic REPLs embedded in apps, making it easier to examine state of running app.

--- Bootstrapped ClojureScript FAQ

簡単な使用例

selfhosted-cljs-example https://github.com/ykomatsu/selfhosted-cljs-example

  • Self-Hosted ClojureScriptを動かすために必要な情報はcljs.js名前空間に大体ある
  • cljs.js/analyze-str
  • cljs.js/compile-str
  • cljs.js/eval-str
  • ClojureScriptコンパイラーの最初の状態はcljs.js/empty-stateで入手できる

実際の使用例

Links