Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Apropos Clojure - July 28, 2021

Show notes - July 28, 2021

We are no longer publishing to YouTube! We have a site now: https://apropos-site.vercel.app/

Domain coming soon!

Show page: https://apropos-site.vercel.app/episode/54

Discord - Join if you want to watch us live or chat! https://discord.gg/xEsH53Ey

Follow us on Twitter for updates - https://twitter.com/AproposClj

Guests

Building a mobile app in Clojure with GraalVM

Summary from @borkdude

You compile a Clojure project to a binary like you would normally do with GraalVM, similar to what babashka does, but you compile specifically for iOS, using some LLVM stuff that GraalVM supports (this part Adrian knows, I really don't).

This library exposes some native functions. You can use these functions from a native UI, just like any C library. So you can write the UI in Swift, or whatever is the trend these days. But you can't use any Clojure evaluation anymore, since Clojure = bytecode emitter and you can't eval new bytecode in GraalVM. But you can ship Small Clojure Interpreter (SCI) to interpret some Clojure. This is exactly what babashka does as well: It's a binary with pre-compiled libraries and at runtime you can use interpretation to glue the libraries together.

So what Adrian has done in the shared library is expose an eval function so you can send expressions from the front-end to this library and it will do stuff. And there is also an nREPL implementation for SCI-based projects (same as what ships with babashka), so you can include that as well. The nitty gritty of the UI stuff is what Adrian has figured out, using Skia. He has a library called membrane which is an abstraction over all kinds of UI frameworks like Reagent/React, but also native ones like Skia.

It's still quite experimental, but Adrian managed to get something into TestFlight which I downloaded on my phone and posted on Twitter about. The really hard problem is finding a problem to write an app for 😛. But this is pretty exciting since you can now use Clojure JVM code on your iPhone.

Mobile app repo: https://github.com/phronmophobic/mobiletest/

Example ants demo (from Rich Hickey): https://github.com/phronmophobic/mobiletest/blob/main/examples/ants/ants.clj

Join the TestFlight test group on your iPhone: https://testflight.apple.com/join/GLOKMgFX

#graalvm-mobile Clojurians slack channel: https://app.slack.com/client/T03RZGPFR/C0260KHN0Q0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment