Puzzled by this behavior

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Jun 1 08:39:42 UTC 2022


On Wednesday, 1 June 2022 at 08:22:24 UTC, Ola Fosheim Gr wrote:
> On Wednesday, 1 June 2022 at 07:54:04 UTC, FeepingCreature 
> wrote:
>> implementing dynamic scoping. But D is lexically scoped for 
>> functions, not just with nested functions but with every 
>> language element.
>
> The functions foo and bar are in the same scope, checking for 
> initialization before use is not strictly related. Also goto 
> can jump to a forward label, so C allows some forward 
> references.

Well, I guess you can say that every new name creates a new scope 
as it shadows the outer scope in order. Anyway, a prototype isn't 
a bad trade-off.

(Btw IIRC «dynamic scope» is a completely different concept, that 
means the lookup is done down the call-graph. E.g. if function 
f() calls g() and f() has ```x```then g() will access f()'s 
```x``` when mentioning ```x```.)




More information about the Digitalmars-d mailing list