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

Class variable #1086

Closed
wants to merge 2 commits into from
Closed

Class variable #1086

wants to merge 2 commits into from

Conversation

BCSharp
Copy link
Member

@BCSharp BCSharp commented Jan 12, 2021

This is another take on #723 (an alternative to #734). As such it partially undoes #721 (parser changes).

It is still a hack, because __class__ variables are now manages as global variables named $__class__NN, not an ideal situation, but it is meant as a proof-of-concept for how a __class__ variable should behave. In particular, it seems that a __class__ variable behaves as a regular class scope variable that just happen to be initialized to the class type. For instance, it is possible to set __class__ to any value, even if it is not a type (e.g. it is possible to set it to a number), while setting the attribute __class__ is guarded against invalid values.

Alternative implementations to global variables:

  1. use an ordinary local variable as __class__, placed in the class scope and lifted to be a closure cell; this is my favourite, but I was unable to get it work (2ac9d8c)
  2. use a closure from the parent scope to place __class__; it works OK but only for non-top-level classes and still pollutes the namespace, this time the local one
  3. use a separate closure from the parent closure, which is managed by the class scope itself; since 2. works, this should be possible as well, but I was unable to get it to work (with the same error as with 1., so maybe I am overlooking something) (2d95476)
  4. use a separate dedicated storage that is out of sight, perhaps as part of the context

@slozier @isaiah @in-code-i-trust

@slozier
Copy link
Contributor

slozier commented Mar 6, 2021

Closing this in favor of #1087.

@slozier slozier closed this Mar 6, 2021
@BCSharp BCSharp deleted the class_variable branch July 27, 2022 17:44
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

Successfully merging this pull request may close these issues.

None yet

2 participants