Skip to content
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

Refactor: Mixin semantic unification and simplification. #92

Closed
Peefy opened this issue Jun 15, 2022 · 1 comment
Closed

Refactor: Mixin semantic unification and simplification. #92

Peefy opened this issue Jun 15, 2022 · 1 comment

Comments

@Peefy
Copy link
Contributor

Peefy commented Jun 15, 2022

Enhancement

Semantic

  • The visibility/reference of a Mixin to its host variables can only be achieved through the Protocol (similar to the interface for property access). When the host uses a Mixin, it must satisfy the Protocol property constraints (satisfying the type partial order relationship), and it is one-way, that is Mixin is visible to the properties of the host individually, different mixin attributes are invisible to each other, and the host is invisible to the properties in the mixin.
  • Mixin can only do merged incremental modification, cannot reassign the existing properties of the host, but can define the properties that the host does not have.
  • Automatic merging of configuration blocks with the same name in mixins and schemas that use the merge operator :.

The KCL code is

schema Person:
    mixin [FullNameMixin]
    firstName: str
    lastName: str
    age: int
    id?: int

# protocol specifies what properties the host of the mixin must have
protocol FullNameProtocol:
    firstName: str
    lastName: str

mixin FullNameMixin for FullNameProtocol:
    fullName: str = "{} {}".format(firstName, lastName)
    
alice = Person {
    firstName = "Alice"
    lastName = "Green"
    age = 10
    id = 1
}

The output YAML is

alice:
firstName: Alice
lastName: Green
age: 10
id: 1
  fullName: Alice Green
@Peefy
Copy link
Contributor Author

Peefy commented Feb 8, 2023

Close with #404.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants