Call-by-name functions #45
Labels
area: AST
Issues which affect AST code
area: syntax
Syntactical changes to the language
change: expansion
A change which includes new features, improvements, or APIs
I'm writing a regression in the
typeck
branch, to go back to call-by-argument functions. The current master (as of 8a20dc5) requires that all parameters to functions be named, and allows variables to be used as the names:The exception for this is single argument functions - for them, the naming rules are ignored.
Call by argument name
Okay, here's how it should work:
When you're writing a function, you can ask for named parameters after a certain index with the keyword
named
:The compiler should also emit a warning if you have two or more arguments of the same type which are not named.
What about when you're calling a function? We enforce call by parameter name. All parameters after
named
must be call-by-name in callers.This is done by the syntax
paramName: <expr>
.If we allow callers to specify names whenever they want, however, the caller cannot rename parameters without breaking API compatibility. This may be a worthwhile tradeoff, however.
Motivations
As with other languages with call-by-name functions (especially statically typed ones, like C#), our motivation is to make code more readable.
I can imagine guidelines for named arguments reading as:
Use named parameters for parameters of a function that
The text was updated successfully, but these errors were encountered: