Update Block Results

Glen Whitney 2024-09-12 23:22:44 +00:00
parent d32e4b7e89
commit 223b914c24

@ -118,3 +118,9 @@ During the meeting, we weighed the merits of two approaches:
- A block in Husht returns `()` by default. Adding some token to the final expression will cause it to be returned. - A block in Husht returns `()` by default. Adding some token to the final expression will cause it to be returned.
Both approaches sometimes require the last statement in a block to include an *extra token*. One advantage of returning `()` by default is that the extra token communicates the author's intent: "I want this value to be returned." When the last statement is returned by default, the extra token communicates something more contingent on implementation details and less related to the author's intent: "This final expression happens to return a value other than `()`, but I don't want that value to be returned." Both approaches sometimes require the last statement in a block to include an *extra token*. One advantage of returning `()` by default is that the extra token communicates the author's intent: "I want this value to be returned." When the last statement is returned by default, the extra token communicates something more contingent on implementation details and less related to the author's intent: "This final expression happens to return a value other than `()`, but I don't want that value to be returned."
### Sep 12 tentative proposal
This is a mild change to Glen's first proposal: we use the Rust convention that unterminated statements propagate their value and semicolon coerces that to Unit, _except_ for the last statement of a function that is either untyped or explicitly typed to return Unit (by name, not an alias, so we can look for it syntactically). These statements will automatically have the semicolon inserted, because there is no way we could need to use their values.
We will see how much "semicolon jockeying" we need to do and adjust the principle if need be, perhaps adding a "ship this expression out" symbol.