Tsoding - How Not to Market Your Language Features

Patrick Schluter Patrick.Schluter at bbox.fr
Thu Apr 3 09:03:51 UTC 2025


On Wednesday, 2 April 2025 at 15:16:43 UTC, Timon Gehr wrote:
> On 3/31/25 13:23, Patrick Schluter wrote:
>> On Thursday, 27 March 2025 at 14:21:11 UTC, Ali Çehreli wrote:
>>> I haven't watched it yet. I'm just attempting to beat you to 
>>> announce it. :p
>>>
>>>   https://www.youtube.com/watch?v=_kRsbu82zqs
>>>
>>> Ali
>> 
>> I was wondering. At around 1:20:00 he is experimenting with 
>> opApply() to make his Array foreach-able. He makes an obvious 
>> error of shadowing i parameter with the loop index i. I was 
>> wondering why the compiler didn't catch this shadowing as it 
>> does in general do recognize shadowed variables.
>
> Can you show the code that you mean or give a more accurate 
> time stamp? I only see the _delegate's_ parameter `i` at 
> 1:19:41, which does not lead to shadowing, as the only actual 
> parameter in scope within `opApply` is `dg`.

Timestamp 1:17:27

     int opApply(scope int delegate(size_t i, size_t a, size_t b, 
ref T) dg) {
         for (size_t i = 0; i < length; ++i) {
             int result = dg(i, 69, 420, items[i]);
             if (result) return result;
         }
         return 0;
     }

Ok, now that I have typed the code, I see why there is no 
shadowing. The `size i` as parameter of the delegate declaration 
is just that, a declaration, not a definition.
During video viewing, it went by so fast that it looked like a 
parameter list of `opApply`.


More information about the Digitalmars-d mailing list