List of all permitted operations on scope function parameters.

Loara loara at noreply.com
Sat Apr 16 06:57:01 UTC 2022


On Friday, 15 April 2022 at 23:17:26 UTC, Salih Dincer wrote:
> On Friday, 15 April 2022 at 21:57:28 UTC, Loara wrote:
>> Documentation page 
>> https://dlang.org/spec/function.html#scope-parameters about 
>> `scope` function parameters says simply that a scoped 
>> parameter "can't escape that function's scope". This concept 
>> can be very tricky with some non-trivial algebra of struct's 
>> members and pointers, so I think it's better to provide a 
>> general algorithm to state if an expression/statement 
>> involving one or more `scope` function parameters is valid or 
>> not.
>
> **scope** and **return** are both my nightmare.  ```scope(exit) 
> // blah blah```, no problem and even ```return result``` It's 
> okay...
>
> But when I come across these elsewhere, it's scary.  Especially 
> in function parameters!
>
> @SDB79

Exactly, but i think that if correctly defined `scope` can be a 
very powerful tool, in particular when dealing with `shared`: we 
could define a safe `critical` block (or reuse `synchronize` 
blocks) guarded by mutex in order to automatically cast the 
selected `shared` variables as `scope` (via `scope ref` 
parameters).


More information about the Digitalmars-d mailing list