logoalt Hacker News

MrResearcherlast Sunday at 4:13 PM1 replyview on HN

It's still not clear to me how you can make two comptime closures with different contents and pass those as a functor into the same function. It needs to have a sort of VTable to invoke the function, and yet since the contents are different, the objects are different, and their deallocation will be different too. Defining VTable in zig seems to be a pretty laborious endeavor, with each piece sewn manually.


Replies

zoogenylast Sunday at 5:51 PM

There was a recent Zig podcast where Andrew Kelley explicitly states that manually defining a VTable is their solution to runtime polymorphism [1]. In general this means wrapping your data in a struct, which is reasonable for almost anything other than base value types.

1. https://youtu.be/x3hOiOcbgeA?si=Kb7SrhdammEiVvDN&t=7620