-
Notifications
You must be signed in to change notification settings - Fork 8
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
Overload / use defaults for range() function #102
Comments
@plajjan Absolutely! It's just that the I've deliberately left out the part of the type-checker that would allow function arguments to be absent, for now. Will need some work before it can fly. |
Hmm, would it be "leaving out arguments", isn't it about "supporting default values for arguments", which then become optional, no? Maybe it's both, just depends on perspective... |
Yep, that's true, but the tricky part during type-inference is matching the actual and expected argument lists in such a way that still allows the actual list to be shorter. It's that part that's not fully implemented, the definition of functions with default argument values is actually already supported. |
Now that we have default argument values we support If someone tries to do |
@sydow I note our numpy arange() function has a different type signature. Is this intentional or should it also be aligned on range()? class range (value):
def __init__(self, start: int, stop: ?int, step: ?int) -> None:
NotImplemented def arange(start: ?int, stop: int, step: ?int) -> ndarray[int]:
NotImplemented Looks like arange() is trying to define first start argument as optional, but that can't ever work, can it? also see above comment.. |
I have updated all our uses of |
Python actually plays a little trick here, and so do we, by interpreting the first parameter as a single stop value if no other parameters are present. So the proper parameter names should perhaps not be start and stop but rather something more suggestive of the interpretation that actually takes place. Interestingly, the Python documentation cheats boldly here, claiming that range is "overloaded" with two alternative definitions:
No such overloading is possible in Python, though, but neither is the informal signature syntax that the documentation relies on. So I guess they can get away with it :-) Regarding Calling it start_or_single_stop is perhaps accurate but a bit clumsy. Any better suggestions? |
I think we can just keep the current argument names and explain in text what it does. |
The
range()
functions currently requires three arguments:In Python, it is possible to invoke with one, two or three arguments:
I think we should allow the same in Acton.
The text was updated successfully, but these errors were encountered: