Closed wilsonwang371 closed 3 months ago
In fact, KCL currently supports defining member functions for schemas and can omit self.
schema Person:
firstName: str
lastName: str
getFullName: () -> str = lambda {
firstName + " " + lastName
}
p = Person{
firstName = "Alice"
lastName = "White"
}
fullName = p.getFullName()
The output is
p:
firstName: Alice
lastName: White
fullName: Alice White
Of course, this is not as complex in configuration languages, just defining it is enough.
schema Person:
firstName: str
lastName: str
fullName: str = firstName + " " + lastName
p = Person{
firstName = "Alice"
lastName = "White"
}
fullName = p.fullName
Is it possible to support
getFullName = lambda {
firstName + " " + lastName
}
as well?
This is possible, but in KCL, schema members without type annotations are treated as private.
this is not very straightforward. can we have something like underscore in python or upper/lower case in golang. i know this already conflict with current version.
Make sense. We are exploring the possibility of simplifying KCL and clarifying its semantics. Perhaps this situation will change in future versions. In addition, we will also provide more user-friendly prompt information for additional enhancements.
Hey @Peefy , made the PR #377
General Question
is it possible to support schema lambdas (class methods) in kcl. we can have a self keyword which can be used to access a readonly instance.