I’m trying to learn this language, and it’s great, but it is hard, but due to lack of documentation/examples more than anything else, which I understand is low priority (deferred during major development, til 1.0) and that is totally fair - not a criticism.
But, I’ve looked through the documentation, gone through the overview, gone through the list of operators, and I can’t find a mention of what |this| is or how it works. From context clues I figure it’s a variable capture. But I don’t know specifics and want to read about it. When can it be used? It’s shown to be used in optionals with ifs, iterators within whiles, and with catching:
if (optional_foo) |foo| {
while (it.next()) |item| {
_ = foo() catch |err| return err;
So, you can use it when a preceding expression returns a value…? (Actually, you must use it if you can - just learned that from the compiler, which is excellent, it points you in the right direction.) But from that logic, that would imply you could do:
test "capture as declaration" {
const math = @import("std").math;
const two = math.floor(math.e);
math.floor(math.pi) |three| {
_ = two + three;
}
}
But, that fails, so we can’t do that, and it would be weird anyways. But, can you understand my confusion?
Anyways… Is this anywhere in the docs? Also surely I’m overthinking this, but it’s just introduced sans explanation.