One of the advantages of working with Clojure is that it can be used on top of the JVM as well as in the browser. This is possible thanks to the Cloju

/ How to add a Clojure REPL to a web page

submited by
Style Pass
2023-03-24 09:00:02

One of the advantages of working with Clojure is that it can be used on top of the JVM as well as in the browser. This is possible thanks to the Clojurescript compiler, which takes your .cljs files and turns them into optimized Javascript with the help of the Google Closure compiler. The compilation is run during the project build stage, creating large .js files that will then be embedded into a webpage. Other than using the same language for backend and frontend development, a great advantage is that, in theory, you can even run Clojurescript directly in the client browser.

I got inspired after trying the cool project Try Haskell and it made me thinking about how I could replicate it, allowing users to try Clojure syntax in a REPL on a web page. So I started searching for a way to embed a working Clojure REPL in a small web app.

There are various way to achieve this. The old method was using the self-hosted cljs compiler, but there’s a simpler approach. Thanks to SCI, the Small Clojure Interpreter is now possible to write and execute Clojurescript code on top of Javascript; this means it can be executed in the browser.

Leave a Comment
Related Posts