Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's indeed nice for math expressions.

I'm a bit sad there seems to be no interest in adding interpolation syntax to Zig. While anonymous tuples work well for shorter expressions, they can get confusing for larger textual templates or DSLs, imo.

I've been experimenting with Zig for WASM, for example, and the readability of HTML templates suffers. I'd love to be able to pass arguments inline, and while we can do that with anonymous tuples, the added noise makes it annoying to use in practice. I believe Javascript's template literals, out of all things, would be a fitting inspiration for a little syntactic sugar on top of anonymous tuples:

  var tuple_params = html.create("{} ... {} ... {}", .{a, b+c, observable});
  
  var tuple_inline = html.create(.{"", a, " ... ", b+c, " ... ", observable, ""});
  
  // equivalent to tuple_inline
  var tuple_sugar = html.create(`{a} ... {b+c} ... {observable}`);


zig's standard library `std.fmt` functions support named arguments as well:

  var tuple_params = html.create("{[foo]} ... {[bar]} ... {[observable]}", .{
    .foo = a,
    .bar = b+c,
    .observable = observable,
  });
It's verbose and explicit to be sure, but quite readable IMO.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: