News for hackers. Stuff that matters.
Re:Show HN: Tiny 1k Rust binary on Windows by acqq on Wednesday December 02, 2020 @09:36AM (#25276674)
What name would you use after seeing the implementation of the functions called?

std/debug.zig:

    pub fn print(comptime fmt: []const u8, args: anytype) void {
        const held = stderr_mutex.acquire();
        defer held.release();
        const stderr = io.getStdErr().writer();
        nosuspend stderr.print(fmt, args) catch return;
    }

io/writer.zig:

    pub fn print(self: Self, comptime format: []const u8, args: anytype) Error!void {
        return std.fmt.format(self, format, args);
    } 
std/fmt.zig:

    pub fn format(
        writer: anytype,
        comptime fmt: []const u8,
        args: anytype,
    ) !void {
       ...
It's all based on the language features and the actual implementations of zig's standard library code, and at least I don't see anything "wrapped" there, and nothing what C++, C or asm programmers understand as "a macro".
Re:Show HN: Tiny 1k Rust binary on Windows by mcountryman on Wednesday December 02, 2020 @03:51PM (#25281443)
Very well optimized inlined functions?

I didn't actually check the zig std source. I was referring to what I was seeing in radare2 :)

Re:Show HN: Tiny 1k Rust binary on Windows by acqq on Wednesday December 02, 2020 @04:16PM (#25281768)
In zig there's a concept of "comptime" -- note that fmt parameter is marked as such. It's more than just inlining.

https://ziglang.org/documentation/master/#comptime

See an example calling firstNPrimes. "When we compile this program, Zig generates the constants with the answer pre-computed." "Note that we did not have to do anything special with the syntax of these functions. For example, we could call the sum function as is with a slice of numbers whose length and values were only known at run-time."

Then see "Case Study: printf in Zig"

Re:Show HN: Tiny 1k Rust binary on Windows by mcountryman on Wednesday December 02, 2020 @06:31PM (#25283266)
I'm a little short on time so I didn't read through all of it but, comptime generics sounds similar to how rust compiles generics and comptime parameters are similar to const fns although zig appears to have more control over what is deamed "compile time".