-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Rename var
to anytype
for generics
#4820
Comments
junon = me :) Sounds good to me. |
Isn't the |
The plan for this is the same for other keyword changes. zig fmt auto correcting code for 1 release cycle, remove legacy syntax in the next release cycle. |
The entire |
I think |
Is there any allowance in Zig's grammer where name: specifier does not mean 'The storage called name is of type specifier'? If not, then the structure of the : disambiguates the meaning. |
Easier to remember two keywords that are not context dependent IMO, but I would still prefer // isBuffer and isLogger are type predicates: fn(type) bool
fn filterProcess(input: anytype(isBuffer), output: anytype(isBuffer)) anytype(isLogger) {
// dostuff
}
// more readable imo
fn filterProcess(input: var(isBuffer), output: var(isBuffer)) var(isLogger) {
// dostuff
} Same if there was a way to make aliases (item 3) of the generic type parameter. // not immediately obvious these "types" are just aliases of the generic type
fn filterProcess(input: Buffer, output: Buffer) Logger {
// dostuff
}
// with var or anytype "wrapping" the alias:
fn filterProcess(input: anytype(Buffer), output: anytype(Buffer)) anytype(Logger) {
// dostuff
}
fn filterProcess(input: var(Buffer), output: var(Buffer)) var(Logger) {
// dostuff
} If there won't be any "upgrades" to the generic type parameter though, I think |
As an aside, is there a sensible reason that the example code isn't able to coerce floating point types? In order to make the fn add2(input: anytype) @TypeOf(input) {
return input + @as(@TypeOf(input), 2);
} This is clunky. Am I missing something here? Also, I'm really not a fan of the |
Introduce the keyword
anytype
to replacevar
in generic function declarations:Benefits:
var
means.var
in the placeDownsides:
Credits go to @fengb and @Qix- for proposing the idea in IRC 👍
The text was updated successfully, but these errors were encountered: