p'lisp for Clojure people
For: People who already write Clojure.
p'lisp runs Clojure on a pocket calculator with a 32-bit microcontroller (an RP2350) and no JVM. The language is Clojure: the same reader, the same core names, persistent collections and a live REPL. It is a new implementation, written in Rust, so this page says plainly where it differs.
Try it now
Open the Workbench, press REPL and type at the user=> prompt. These run as written (this page's examples are run by our tests against the real evaluator):
user=> (map inc [1 2 3])
(2 3 4)
user=> (->> (range 10) (filter odd?) (reduce +))
25
user=> (update {:a 1} :a + 10)
{:a 11}
user=> (frequencies "hello")
{\h 1, \e 1, \l 2, \o 1}
user=> (/ 1 3)
1/3
user=> (+ 0.1 0.2)
0.3
What you get
- The core you know. Over 400 functions and macros from
clojure.core,clojure.string,clojure.setandclojure.walk. The reference lists every one, and each is checked against real Clojure. - Persistent collections. Lists, vectors, maps, sets, lazy sequences and transducers.
- State. Atoms, dynamic vars with
binding,letfn, metadata. - Polymorphism. Multimethods, and protocols with
defprotocolandextend-type. - Macros.
defmacroand syntax quote work in the Workbench. Your macros expand on your computer before the code goes to the calculator. - Shared code.
.cljcfiles and reader conditionals, with the feature:plisp. Real libraries load: our tests run most of medley unchanged. - A live REPL. Redefine a function while your app runs and the next call uses the new one.
What is different
- No Java. There is no JVM, so there is no interop: no
Foo.constructors, no class names, noinstance?, and no.methodcalls except.getMessageand.getCauseon an error. Library code whose only branch is JVM code does not run; a#?(:plisp ...)branch fixes it. - Numbers are a calculator's. Decimals are exact, so
(+ 0.1 0.2)is0.3.+,-,*,incanddecnever overflow; they grow into big integers. - Macros live on the computer side. The calculator has no macro expander of its own, so typing
defmacroon the calculator's keypad is refused. Write macros in the Workbench. - Small memory. A calculator has far less memory than a laptop. Deep recursion stops at a fixed depth with a clear error, instead of a stack overflow.
- Not yet: records and types (
defrecord,deftype,reify), sorted collections, and dates and times. Futures and threads are not planned.
Next
- Write your first app: Clojure apps on p'lisp are pure functions that return effects as data, in the style of the Elm architecture and re-frame.
- Look up a name in the Clojure reference.