You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there's no way to set default values for strucs. I don't want this to turn into fully fledged constructors, but it should work for constants in the same way as default arguments work. They would be substituted verbatim inside the struct literal when creating the struct.
Additionally I would allow const values which don't take up space inside the stucture but actually behave like functions. Those would work with polymorphism tho, this is mainly useful for being able to override functions in interfaces with a constant value without having to write out the whole function.
It would look something like this:
type S = struct {
const constant: int = 20
foo: int = 20
}
Maybe it makes sense to only allow these const parameters at the beginning/end of the structure because otherwise when you mix them with regular values the semantics for assigning values by index becomes really weird.struct inititalization by index was removed
One use case for these const values are setting flags for an interface like this:
type Kind = enum {
KIND_A
KIND_B
}
type I = interface {
def kind -> Kind
...
}
type S = struct {
const kind = Kind::KIND_B
...
}
// As opposed to writing something like this:
def kind(s: S) -> Kind { return Kind::KIND_B }
The text was updated successfully, but these errors were encountered:
Currently there's no way to set default values for strucs. I don't want this to turn into fully fledged constructors, but it should work for constants in the same way as default arguments work. They would be substituted verbatim inside the struct literal when creating the struct.
Additionally I would allow const values which don't take up space inside the stucture but actually behave like functions. Those would work with polymorphism tho, this is mainly useful for being able to override functions in interfaces with a constant value without having to write out the whole function.
It would look something like this:
Maybe it makes sense to only allow these const parameters at the beginning/end of the structure because otherwise when you mix them with regular values the semantics for assigning values by index becomes really weird.struct inititalization by index was removedOne use case for these const values are setting flags for an interface like this:
The text was updated successfully, but these errors were encountered: