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.
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo 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.
Get unlimited access to Tinycanva: Clojure for React Developers, plus 70+ \newline books, guides and courses with the \newline Pro subscription.
[00:00 - 00:18] 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.
[00:19 - 00:31] 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.
[00:32 - 00:45] 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.
[00:46 - 00:59] 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.
[01:00 - 01:12] 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.
[01:13 - 01:29] 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.
[01:30 - 01:37] But the community ports are not always feature complete. Closure provides constructs to interact with the host language.
[01:38 - 01:55] 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.
[01:56 - 02:05] 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.
[02:06 - 02:14] 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.
[02:15 - 02:25] 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.
[02:26 - 02:30] And you can transparently access most of the host features.