-
Notifications
You must be signed in to change notification settings - Fork 196
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
User-Defined Constant Functions #2222
Comments
I think we'd have to require the So, here's my attempt of a definition:
This definition allows you to access However, we do not want to require every implementation of A solution might be to make the
Then all non-constant sub-classes can ignore the problem, but constant subclasses are required to be consistent with the superclass. |
Aren't you looking for a |
Seeing as this idea didn't reveal any glaring flaws when I asked at #1296 (comment), I figured I'd make it into a full feature request and see what comes of it.
The suggestion is for users to be able to define their own constant getters, operators, and functions with a restricted set of language features, which can be run at compile time. Naturally, interacting with non-constant/final members of classes wouldn't be possible. Recursion and conditional iteration probably should be prevented too if you don't want to risk the compiler never halting.
It might look something like:
It'd be cool to have full code block bodies with local variables, if and switch statements, maaaaaybe for-each loops, whatever else that can be done without side effects... But I'm not sure how much complexity that'd add, and expressions alone would be make for a helpful addition to the language.
Could make for a partial solution to #2219 - if some of those members could be defined as constant then they wouldn't have to be directly included in the language spec. I imagine some of the more fundamental ones like
List.operator[]
will still need to be, though.I'm sorta realizing the ramifications and potential complications of a feature like this as I type it up and I'm sure I don't have the complete picture, so I'd be glad to hear others' thoughts on it.
The text was updated successfully, but these errors were encountered: