imports in functions

Robert Clipsham robert at octarineparrot.com
Mon Jun 13 04:39:20 PDT 2011


On 12/06/2011 22:15, Walter Bright wrote:
> Nobody seems to have noticed yet, but yesterday I removed the
> restriction preventing import declarations from being used in functions.
> These now work:
>
> void test1()
> {
> import std.c.stdio;
> printf("hello world\n");
> }
>
> void test2()
> {
> static import std.c.stdio;
> std.c.stdio.printf("hello world\n");
> }
>
> https://github.com/D-Programming-Language/dmd/commit/d5fbd53aa8d8452dce2514944575e654d387477a
>
>
> I believe this can lead to better encapsulation of code, especially when
> using mixins, versioning and other conditional compilation constructs.

I did notice this - I think it's awesome. So many times when debugging 
code I've attempted to write import std.stdio; in the function, then had 
to move it away from the code I was debugging - of course this left a 
stray import because I forgot about it :3

-- 
Robert
http://octarineparrot.com/


More information about the Digitalmars-d mailing list