In Zig, the top level scope of a file is a struct; you have fields.
Code is great.
In this project, I don't think this is an exact thing we should copy. But the pattern is interesting. I think it would be cool to support.
Before this idea can be truly considered we need @import and module declarations, but i imagine syntax like this.
// Tokenizer.wl
/// Documentation comment for Tokenizer
... struct Tokenizer {
code: string,
pos: int,
}
fn tokenize(...) { ... }
Then, using @import("Tokenizer.wl") will return you Tokenizer, and you could Tokenizer.tokenize to access the function.
Alternatives could be toplevel struct, module struct, or something else.
I like this better than Zig's form because we can have top-level enums and unions.
Milestone: 0.3.0.