-
Notifications
You must be signed in to change notification settings - Fork 257
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
feature request: naming function return values #5
Comments
Let's go with the syntax in the first suggestion above, namely:
The identifier A function that declares a name for its result value should still be allowed to call itself in the postcondition like before. In other words, the function If there's a way for Dafny not to mark the "I'm just trying to denote the result value"-calls that Chris mentions as recursive, that would be great. As it stands now, the Dafny front end cannot tell the difference, but instead this is relegated to a semantic check done by the verifier. I suggest the following improvement, which at least would cover the most common case: For a function Thanks, |
… return value as a recursive call. part of fix for #5
Dafny methods have named return values, while Dafny function return values are anonymous:
This is nice and concise when you never have to refer to the return value by name. But sometimes you need to refer to the return value in an ensures clause. Currently, this is done by referring to the whole function call applied to its arguments:
There are two issues with writing a call like "f(x, y)" in ensures clauses. First, the call is often very long to write -- not just "f(x, y)", but "myverylongfunctionname(myverylongargument1, myverylongargument2, myverylongargument3)". This can be mitigated somewhat by binding the return value to a shorter name using a "var" (let) expression, but this doesn't work across multiple ensures clauses. Second, when Dafny sees the function call "f(x, y)" in an ensures clause, it tags the function as recursive, which brings in extra machinery for layers and fuel.
These two issues could be solved independently. But both issues could be solved together with an optional named return value, something like:
Boogie, for example, already supports optional named return values from functions.
The text was updated successfully, but these errors were encountered: