On Tue, 13 Dec 2016 17:33:24 -0500, Andrei Alexandrescu wrote:

> Destroy.
> 
> https://github.com/dlang/DIPs/pull/51/files
> 
> 
> Andrei

> Inside any function, with (Import ImportList) is a statement that
> introduces a scope.

So I can't write:

  with (import std.stdio, std.conv)
  int count = readln().to!int;
  assert(count > 0);

It is in fact entirely equivalent to write:

  {
    import std.stdio, std.conv;
    int count = readln().to!int;
  }

I think I'd just put a line in the DIP: for consistency, this syntax 
works anywhere a with statement is currently allowed, but it's not 
recommended to use it inside function bodies in general.

> This extension removes an unforced limitation of the current with
> syntax (allows it to occur at top level)

In other words, another aspect of this DIP is that I can write:

  module foo;
  static import std.traits;
  static import bar;
  with (std.traits)
  {
    template Foo(T) if (isAbstractClass!T) {}
  }
  with (bar.SomeEnum)
  {
    enum something = SomeEnumValue;
  }

Which *almost*, but not quite, obviates the "you can put the import list 
in the with clause" part of the DIP. It's got all the same benefits for 
reading, but you might occasionally have to jump to the top of the file 
to add a new static import.

Reply via email to