Understanding the Benefits of Clojure's Hosted Nature

Clojure is neither compiled nor has its own VM. Instead, it runs on VMs of other languages. In this lesson, we'll learn about official and unofficial ports and support status.

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the Tinycanva: Clojure for React Developers course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to Tinycanva: Clojure for React Developers, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Tinycanva: Clojure for React Developers

Programming languages need a mechanism to be converted from source files to something that can be executed. In compiled languages like C or C++, the source code is first converted to assembly code, then to object code, and then some linker magic is used to create an executable. Languages like Java operate at a higher level of abstraction. Instead of worrying about how the assembly code would be computed, the Java source code is compiled to bytecode. This bytecode can then be run on JVM that takes care of the lower level abstractions. Another set of languages like CoffeeScript are just converted from one syntax to another. Closure is a hosted language. It targets the virtual machines of other languages. In Java land, Closure source code is converted to dot class files which can run on top of any JVM. In Java script land, Closure is transpiled to common JS or ASM modules similar to pure script or reason ML. As of now, there are three official ports for Closure. Closure without a suffix that targets the JVM, Closure script that targets JavaScript, and Closure see a lot that targets the common language runtime. Apart from the official ports, there are many community ports that can target other runtimes. But the community ports are not always feature complete. Closure provides constructs to interact with the host language. You can use any library in the host ecosystem and most of the language features available at the host. This means that when you are writing Closure script, you have access to JavaScript promises and when you are writing Closure, you have access to Java's async module. It is also possible to write code that targets multiple runtimes at once. This can be achieved using the concept of reader conditionals and Closure common files. This is an advanced topic and we will not delve into this at the moment. In conclusion, Closure runs on top of other language VMs. It lets you tap into existing ecosystems like NPM and Maven. You need to learn it just once and use the same API to target various runtimes. And you can transparently access most of the host features.