News for hackers. Stuff that matters.
Re:Zig's dot star syntax (value.*) by 3836293648 on Saturday March 08, 2025 @09:22PM (#43305581)
Postfix is only superior when you have lots of things to chain. C doesn't have any chaining at all. f(g(x)) is just as good as f(g(x))
Re:Zig's dot star syntax (value.*) by card_zero on Sunday March 09, 2025 @04:29AM (#43307279)
Gotta escape those asterisks so you don't output italics.

f(*g(*x)) is just as good as f(g(x*)*)

Hmm, function names go before parentheses, that looks like a good reason for dereferencing to be prefix too, otherwise they end up a long way apart.

But in the back of mind I'm thinking "semantics cause pointless fussy arguments, all code is ugly, let's stop programming in text somehow".

Re:Zig's dot star syntax (value.*) by 3836293648 on Sunday March 09, 2025 @06:17AM (#43307798)
Oh yeah, forgot HN supported some markdown.

But this is literally not semantics. Semantics is everything of value, this is just syntax.

Re:Zig's dot star syntax (value.*) by card_zero on Sunday March 09, 2025 @08:07AM (#43308376)
Sorry, yes, syntax. I was equating it to "purely semantic argument", arguing about the meaning of words. Here about it's where to put symbols.
Re:Zig's dot star syntax (value.*) by dfawcus on Sunday March 09, 2025 @06:49AM (#43307904)
One is able to chain calls in C via:

    x()->g()->f();
At least one person at Bell Labs historically used that scheme for some graphics program.

All it requires is that the function returns a pointer to a struct which itself contains function pointers.

C also allows the dot form if you really want it:

    x().g().f()
Simply by returning structs, and for all compilers that I know if, such end up using a hidden pointers to structs.

Now to make it a bit more usable, one needs a bit of planning so that either of these can be done:

    x(&x_out).g(&g_out, x_out).f(&f_out, g_out);

    x(&x_out)->g(&g_out, x_out)->f(&f_out, g_out);
(I'd suggest the latter is now the more readable of the two).

Where there is a VFT in each of the xxx_out structures, and the calls simply returns the VFT, while the whole abstraction is stored/returned via the out arguments.