News for hackers. Stuff that matters.
Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by judofyr on Thursday July 15, 2021 @05:28PM (#27850362)
I was actually thinking about writing a “macro” (i.e. function) which takes in a math expressions as a string and an anonymous struct for these use cases:

    eval("Ax + v", {.A = …, .x = …, v = …})
Wouldn’t that be cool?
Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by mkishi on Thursday July 15, 2021 @07:03PM (#27851128)
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}`);
Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by ifreund on Thursday July 15, 2021 @07:28PM (#27851295)
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.
Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by kristoff_it on Thursday July 15, 2021 @06:01PM (#27850624)
That's fairly easy to implement with comptime.