3 ms·
I see it this way, the full signature for defining a variable is: var foo: Foo = Foo{}; There's two ways to shorten it: var foo = Foo{}; var foo:
by hiccuphippo 4mo ago
I see it this way, the full signature for defining a variable is:
var foo: Foo = Foo{};
There's two ways to shorten it:
var foo = Foo{};
var foo: Foo = .{};
It can infer the type of the var from the right hand side; or the type of the right side from the type of the var.
So when you see .{} as an argument, it is inferring the type from the function signature. It happens to be empty only because it's using default values (or is a tuple with 0 items).
Edit: fixed the extra dots.
- dnautics 4mo agothat's not quite right. 1) It's var foo = Foo{...}; (no intervening dot) 2) I think parent commenter is referring to function call use case call_my_func(.{...})
- hiccuphippo 4mo ago1) Ah yes, just typing from memory. Point still stands. 2) Adressed in the last paragraph.
- dnautics 4mo agoPoint being, these two things aren't different (variable assignment and function calls); IIUC they go through the same analysis pathway, result location semantics. https://ziglang.org/documentation/master/#Result-Location-Semantics https://ziglang.org/documentation/master/#Result-Location-Se... It's a little bit weird, since the types flow in the reverse direction than you would expect.