-
Notifications
You must be signed in to change notification settings - Fork 163
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
Add a generic 'no return' value to GAP #829
Conversation
I am thinking whether it is ok to write
or this should be forbidden? |
Obvious bikeshedding:
|
We could forbid returning |
If you forbid returning it, how would that work? Or rather, how could one "use" this return value then? Think of this example: f := function()
local x;
x := Print("x"); # returns nothing, so x = NoReturn
return x;
end; Is that allowed or forbidden? If it is allowed, does it return the value NoReturn, or does it return "nothing"? If it is forbidden, does that mean we insert an extra check at every return to raise an error if the return value is equal to I guess this boils down to asking: What is an actual use case of this? |
I am against making another Boolean value, it's bad enough as it is with I think |
I think I agree it shouldn't be a boolean, that was just quick for a hack :) |
so if one writes a function with several execution branches and will forget to put |
I good guide is |
Continuing (3) from my comment above: As @fingolfin wrote in #464,
Isn't this PR a step in the opposite direction? We now ensure that every function automatically returns a value. This is quite a change. I am not against it, and maybe this would be a good design choice to make early enough. But now even the distinction between procedures and functions for documentation purposes should be adjusted, as otherwise we will not have procedures any more (http://www.gap-system.org/Manuals/doc/ref/chap4.html#X825803DE78251DA6) - perhaps we should then say that procedure returns only this @fingolfin is right that we need to hear more about use cases. Maybe the answer would be to adjust the code that calls such functions to be tolerant when nothing s returned. |
Frank has an alternatve PR #831 with which there is no "real" return value for procedures, but instead, if the "return value" of procedure is assigned to something, that something is implicitly unbound -- this kind of matches the behaviour of Python's On the up side, this avoids introducing a special On the downside, the problem (? if it is one) that code which previously could trigger an error might now pass (when it shouldn't). However, I think in practice it would still error, just a bit later -- though this might make debugging such problems harder. |
I slightly worry that people might get confused when their variables appear to not take a value when they are assigned the return value of a function. I think that patch is better than this one, so the answer is if it's a good idea in general to make a big change to the language, or just provide a simple extension to |
I still like the general idea of replicating Python's That said, it feels like a somewhat bigger change to the language than |
I think this is too big a change, without sufficient support, so I'm closing it. It will still be here if anyone ever wants it. |
This pull request is an experiment in adding a generic, "no return" value to GAP. This adds a new (currently boolean) value 'NoReturn', and any function which appears to have no return value in fact returns 'NoReturn'.
Here are some examples:
This should make no change to any working GAP code, either run interactively or not. The only difference is if you try to assign the result of a function to a variable when the function doesn't return, previously that was an error, now that variable is assigned
NoReturn
.