C2 forum
General Category => Ideas => Topic started by: lerno on October 22, 2018, 09:41:37 PM
-
GNU has an extremely useful extension in expression blocks using ({ ... })
The suggestion I have is to allow C2 to implement those as a standard. There are a few ways to pick the syntax (that I can think of):
- Retain the GNU format
- Let any block ending with an *unterminated* expression return the value of that statement e.g. { foo = bar(); foo } is an expression returning the value of foo, while { foo = bar(); foo(); } is a normal statement.
- Use normal ( ) but allow statments. e.g. ( foo = bar(); foo )
- Use something similar to the GNU format but write explicit return, e.g. [{ foo = bar(); return foo() }] it would still be equivalent to the code above.
Also note that the value-returning macro becomes easy to express for the versions with explicit return. It's simply a macro wrapped in an expression block.