Borrowing Zig’s tagline:
General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
Why is Zig an interesting choice as a lower-level language for Clojure programmers? (compared to Rust, Go or other languages):
Status: Experimental, but proving itself on a few projects.
Hello World:
;; hello.liz
(const print (.. (@import "std") -debug -print))
(defn ^void main []
(print "Hello, world!\n" []))
It will get translated into:
const print = @import("std").debug.print;
pub fn main() void {
print("Hello, world!\n", .{});
}
Run with:
$ liz hello.liz && zig run hello.zig
Hello, world!
FizzBuzz example:
(const print (.. (@import "std") -debug -print))
(defn ^void main []
(var ^usize i 1)
(while-step (<= i 100) (inc! i)
(cond
(zero? (mod i 15)) (print "FizzBuzz\n" [])
(zero? (mod i 3)) (print "Fizz\n" [])
(zero? (mod i 5)) (print "Buzz\n" [])
:else (print "{}\n" [i]))))
See also:
Read the work in progress language guide.
To see how a form is used you can also take a look at samples adapted from Zig docs.
Download Liz and Zig. To compile files from Liz to Zig pass them as parameters:
liz file1.liz file2.liz
# file1.zig and file2.zig will be created
Then use zig run
or zig build-exe
on the generated .zig
files.
Alternatively you can use the JAR:
java -jar liz.jar file1.liz file2.liz
Use .liz
file extension. It works pretty well to use Clojure syntax highlighting, add -*- clojure -*-
metadata to the source file for Github and text editors to apply highlighting.
;; -*- clojure -*-
MIT
Get the source:
git clone https://github.com/dundalek/liz.git
cd liz
Build platform independent uberjar:
scripts/build-jar
Build the native binary (requires GraalVM):
# If you don't have native-image on PATH then you need to specify GRAALVM_HOME
export GRAALVM_HOME=/your/path/to/graal
scripts/build-native
Use Clojure CLI:
clj -M -m liz.main file1.liz file2.liz
Run tests:
clj -Mtest