On 19 March 2025 11:27:11 GMT, Edmond Dantes <edmond...@gmail.com> wrote:
>>
>> You're cheating again - you've put an extra pair of brackets around one
>> expression and not the other, and assumed they'll work differently, but
>that's
>> not the grammar you proposed.
>>
>
>Why am I cheating?

"Cheating" in the sense that you wrote out a "general syntax", and then dropped 
in examples that contradicted that syntax. Saying "it follows this grammar, 
except when it doesn't" isn't very enlightening.



>> spawn (getClosure());
>This is an honest statement, provided that the second parentheses are
>optional. The full notation would be:
>> spawn (getClosure())();

That's not the problem; the problem is that the following are all equivalent 
expressions:

foo()
(foo())
((foo()))
(((foo())))

But you want these to mean different things: 

spawn foo();
spawn (foo());

I think that would be achievable with a new grammar rule for "expression other 
than function call", so you could have: 

spawn_statement:
    'spawn' function_call { compile_function_spawn }
    | 'spawn' expression_not_function_call { compile_closure_spawn }

But from a user's point of view, I hate rules like that which mean subtle 
changes completely change the meaning of the code, in a very specific context.


>The reverse meaning is that if `spawn` is not followed by the `function`
>keyword, then it must be a valid expression that can be enclosed in
>parentheses.
>
>There are some doubts about whether all situations are correct, but so far,
>this is how it works for me:


All of these are examples of the keyword being followed by *a function call*, 
not *any expression*. Which honestly I think is the right way to go.

The "expression" part came into the conversation because I think it's weird to 
force the user to write "function() { ... }" as though it's a Closure 
declaration, but not let them perform obvious refactoring like moving that 
declaration into a variable. 

If it's going to be a special case for an "inline coroutine", just use a 
keyword other than "function", so it doesn't look like an expression when it's 
not, like "spawn block { ... }"; or no keyword at all, just "spawn { ... }"


Rowan Tommins
[IMSoP]

Reply via email to