Identifier resolution, the great implementation defined mess.

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 23 12:13:57 PDT 2014


Am Mon, 22 Sep 2014 00:05:09 -0700
schrieb Walter Bright <newshound2 at digitalmars.com>:

> On 9/21/2014 11:44 PM, Marco Leise wrote:
> > But quite understandable that people expect them to be in the
> > same scope, seeing as there is only one set of {}.
> 
> { } introduce a new nested scope, they do not extend an existing one.

Of course, but

void foo(int x)
{
	int y;
}

appears to the uninitiated as two variables that will only be
visible inside of foo. The notion of a sourrounding parameter
scope only comes up when you dig deep into the language. It
is almost safe to say, without reading the specs or the
compiler source one wouldn't know. (I didn't :) )
 
> > Adding some
> > shadowing warnings should deal with that, so that the earlier
> > example with `text` being hijacked somehow errors out.
> 
> Are how the current lookup rules work (for better or worse) clear to you or are 
> they still mysterious?

Now that I understand that the parameter scope exists I
understand how the lookup happens.
I could say the same about the famous JavaScript WAT video.
Once you understand all the language rules it becomes sane.
That is exactly what a WAT is about: It is a logical
consequence of some hidden context inside the language that
yields totally unexpected results in innocent looking code.

-- 
Marco



More information about the Digitalmars-d mailing list