logoalt Hacker News

jimmyhmiller • yesterday at 9:09 PM • 1 reply • view on HN

Comptime in zig is definitely quite cool, but not quite the same.

Consider this example. https://jimmyhmiller.com/split-shot/#/vm

Make the code a comptime argument in zig and you get "store to comptime variable depends on runtime condition".


Replies

hansvm • yesterday at 9:45 PM

Zig isn't perfect, but I've definitely done this futamura stuff before. It's one of my favourite ways to implement a Forth in Zig (which, incidentally, is the default way that I introduce a backprop library or other DSL as I'm prototyping an idea). Interpreters are dead-simple to write, and I just write an interpreter with a comptime code argument. It definitely works, and the codegen is reasoanble out of the box.

➕ show 1 reply