Skip to content

Comment on How I Built Zig-SQLiteparent

Comments

* arbitrary file I/O. I can take my compile time data and write a python script to put it in a std::array, but I shouldn’t have to.

https://ziglang.org/documentation/0.9.1/#embedFile

I haven't tried, but because it should just be equivalent to a string literal you should be able to further process it using comptime as well.

* non-fixed-sized containers, ie vector

One way is to just have a function count how many entries you need and use arrays. This is all pretty straightforward because comptime.

Real dynamic comptime containers are dependent on making a comptime allocator available. There's a ticket for that: https://github.com/ziglang/zig/issues/1291

* a generic memoization utility in the standard library for caching. If I want my function to handle any input at runtime, but I want to pre-populate a cache at compile time for values that I know will be called, it’s doable but not as easy as it should be. (In general, given the amount of algorithms that rely on memoization, I’m somewhat surprised that Python is the only language I know that makes memoization as easy as a decorator).

I don't think it's possible to use comptime to generate wrapper functions duplicating the signature of a given function, at least I haven't found a way to do so. The function signature has to be spelled out in the comptime code.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.