D import idiom compilation time

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Jan 8 14:28:47 UTC 2019


On Tue, Jan 08, 2019 at 02:13:21PM +0000, Martin Tschierschke via Digitalmars-d wrote:
> On Tuesday, 8 January 2019 at 13:40:51 UTC, Adam D. Ruppe wrote:
> [...]
> > It is by design - UFCS only considered for global symbols. The idea
> > is to simplify the reasoning process for finding .members by
> > eliminating local scopes from the search (supposed to make ide stuff
> > easier, etc)
> > 
> > Whether this is good design or not is left up to the reader.
> 
> So, as a result I can conclude, that real local imports don't work
> togethter with UFCS, and this is disabling any chaining.

Not true. This works:

	void main() {
		// N.B.: local imports
		import std.array;
		import std.algorithm;
		import std.conv;
		import std.stdio;

		// N.B.: UFCS chaining
		"abcdef".map!(e => cast(int) (e - 'a'))
		        .filter!(e => e < 4)
			.map!(e => cast(dchar) (e + 'm'))
			.to!string
			.writeln;
	}

To state more accurately what Adam said, UFCS is considered for
*module-level* symbols. Meaning, the requirement is applied at the site
of definition (it has to be at the top *level* in the module where it's
defined) rather than the site of import (which can be in a local
*scope*).


T

-- 
What is Matter, what is Mind? Never Mind, it doesn't Matter.


More information about the Digitalmars-d mailing list