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

[Question] Class field declaration? #31

Closed
anzhi0708 opened this issue Oct 18, 2022 · 2 comments
Closed

[Question] Class field declaration? #31

anzhi0708 opened this issue Oct 18, 2022 · 2 comments

Comments

@anzhi0708
Copy link

class A():
    let x = 233

This code won't work; can I ask why class fields must be declared without let?

Very cool project by the way ;-)

@klange
Copy link
Collaborator

klange commented Oct 18, 2022

Primarily, this was done to improve compatibility with Python code - it is possible to write a complete class implementation, including class fields, methods, and decorators, which is equally valid in both Python and Kuroko, with some restrictions. The way this was implemented involved parsing class bodies specially - field assignments are a unique syntax in the language and do not work like normal let declarations or even other assignment statements. In fact, in Python class bodies are normal function bodies, but in Kuroko class bodies must consist only of an optional initial docstring followed by field declarations and method definitions, possibly with decorators attached, but can not contain arbitrary statements or control flow structures.

@anzhi0708
Copy link
Author

This is VERY cool, it probably makes Python even more easy to understand, I love the scope design

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

No branches or pull requests

2 participants