How does Planck work?
By default, Planck then starts a REPL. Planck makes entering expressions a little easier by employing a library, making it possible to edit the line as well as access previously entered lines by using the up arrow.
Planck enhances this experience by providing tab completion and brace highlighting:
$ planck -v cljs.user=> (+ 2 3) Evaluating (+ 2 3) (2 + 3) 5
cljs.user=> (first [4 7]) Evaluating (first [4 7]) cljs.core.first.call(null,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [4,7], null)) 4
That's cool when evaluating pure expressions. What about interacting with the outside environment?
Let's say you want to read the content of a file you have on disk, and you enter these forms:
(require '[planck.core :refer [slurp]]) (slurp "foo.txt")
self.inputStream = [NSInputStream inputStreamWithFileAtPath:path]
PLANCK_FILE_READER_OPEN. This capability is made available to you in ClojureScript by having functions like
slurp employ ClojureScript code like
To actually read from the file,
slurp calls another
js/PLANCK_FILE_READER_READ primitive, which invokes code like
[self.inputStream read:buf maxLength:1024]
A few Planck ClojureScript namespaces are bundled with Planck in order to provide mappings onto these I/O primitives, exposing the simple APIs—like
slurp—that you are familiar with:
In a nutshell, that’s really a big part of what Plank is: Some glue between ClojureScript and the native host environment.
Planck wraps all this with some niceties making it suitable as a scripting environment.
One aspect is the loading of custom ClojureScript source files. Let's say you have
src/my_cool_code/core.cljs, and at the REPL you invoke
Planck implements the
require “REPL special form,” which causes bootstrapped ClojureScript—specifically
cljs.js, via its
The nice thing is that
*load-fn* is also used for
:require specs that may appear in namespace declarations in your code, as well as
To top it off, Planck is free to implement
*load-fn* in convenient ways:
With the ability to dynamically load custom ClojureScript code, executing it by mapping it onto native I/O facilities, can ClojureScript can be used as a compelling alternative for your Bash shell scripting needs.