[Design] re-examining the single-statement exception for routines

Hi Chapel Users and Developers —

For most of the language's history, we've supported a syntactic exception for routines whose bodies are a single return statement, permitting:

proc foo() {
  return 42;

to be written without the curly brackets as:

proc foo()
  return 42;

All other single-statement procedures or iterators must be written with curly brackets.

As we work towards stabilizing the language for Chapel 2.0, we've been considering changing the language to remove this special-case, where the current leading proposal is to permit any single-statement routine to be written using a do keyword, like:

proc foo() do
  return 42;


proc bar() do
  writeln("In bar");

In essence, this would make single-statement procedures more similar to single-statement conditionals and loops by supporting a keyword-based form for the single-statement cases while also removing the return-specific special case that exists today.

If you have reactions to this proposal, please share them with us on Single-statement routines and the `return` exception · Issue #20703 · chapel-lang/chapel · GitHub or here on this Discourse topic.


1 Like