https://github.com/leifericf/clj-zig - An Experiment to Bring Low-Level Systems Programming into Clojure As some of you might know, I'm a professional video game developer, and I also dabble in real-time audio processing in my spare time. I've always wanted a way to do native, high-performance systems programming from Clojure to create applications with real-time 3D graphics rendering and audio processing. The idea is to keep the data model and domain logic in Clojure, and use Zig from Clojure for the things that require low-level systems programming. I wanted to explore whether Project Panama could be used to create a "bridge" from Clojure to Zig, which in turn includes C and Assembly, for such use cases. clj-zig is the result of that. Think "Zig as a Clojure library." It lets you write Clojure functions implemented in Zig, with the full REPL-driven, interactive experience. It's a bit rough and clunky, but it sorta' works. I've already used it "in anger" to reimplement https://eido.leifericf.com/'s EDN-to-graphics rendering engine, making it way faster and more flexible, and independent of the JVM/Java 2D. This allows Eido to be used also from any programming language that can produce EDN. I will also share that engine soon (although that engine is a pure Zig project, so I don't know if I'll share it in this channel, or only in the Zig community). This also proved to be a useful tool for Zig programmers who want an interactive development experience. That was just a happy accident.
share in this channel pls π or somewhere on this slack
it's consuming EDN so it is Clojure!
That's what I was wondering. "Does a purely Zig project whose interface is EDN qualify as a Clojure project?" π
any project that is of interest for clojurians is a Clojure project π
I've also implemented a pretty good EDN parser in Zig now. I'm considering pulling that out as a separate Zig library.
> a pretty good EDN parser in Zig now. I'm considering pulling that out as a separate Zig library. > amazing! and since zig can easily use c libraries it would be interesting to compare with edn.c
Doh! I wasnt aware of edn.c Had I know, I would probably have imported that into Zig instead π
> Had I know Oh, god, we're turning into javascript community cerca 2015 - "accidentally" making parsing libraries. π
Nawh, I just suck at knowing things about stuff.
@leif.eric.fredheim Nice work! I am exploring different compilation techniques to target GPU kernels/WASM/SIMD for game/simulation dev as well as a cross-platform Vulkan/WebGL runtime for clj/cljs in https://github.com/replikativ/raster. I am curious about what I am missing from Zig for game devs. Raster (or in general this compilation based approach) gives a fairly tight control over memory locality and computation including transparent IR inspection.
Cool project congrats on the release! The integration with eido sounds really promising, canβt wait to try it. Curious if you looked at Odin before going w Zig? I couldnβt have an opinion about it (never worked in either lang), but Iβve heard/read about Odin as more purpose-built for game dev and graphics.
Thanks! Yeah, I looked into and tried C3, Odin, and Hare in addition to Zig. They're all pretty cool projects. Jai also looks pretty interesting, but it's not publicly available yet.
Thatβs cool ! So was the tooling/installation/distribution aspect the deciding factor?
The tooling around Zig and its reach are far beyond anything else in the same space. But perhaps more important is the principles and philosophy behind it, the grand long-term vision of Zigβs creator, and the way it's structured as a 501(c)(3) nonprofit corporation as opposed to a 501(c)(6). Odin is narrowly focused and, arguably, offers a better developer experience because of that, but it also has fewer affordances. Zig appears to be the most serious and well-organized, and thus the safer bet for the long run.
That said, I don't think Zig or anything else will βkillβ C any time soon for certain use cases. For example, I kept https://mino-lang.org in C99 so that it can be embedded anywhere with zero dependencies. But I've adopted the Zig compiler and tooling stand-alone and gotten a lot of value from that, even without using the Zig language.
For any stand-alone low-level library or application that doesn't need to be compiled into a host application, Iβd likely opt for Zig over C. It depends. But it seems the problem space in which C is the βbetterβ option will shrink slowly but considerably as Zig matures.