December 14, 2016
On Wednesday, 14 December 2016 at 17:09:44 UTC, ketmar wrote:
>> bool equal(R1, R2) : std.range, std.traits
>> if (isInputRange!R1 && isInputRange!R2 && isArray!R2)
>> { ... }
>
> breaks possible selective import. if both modules exports some symbol, we will need to selectively import and/or rename it.

Not necessarily. The first colon is the only special case, afterwards you can use all forms of imports:

>> bool equal(R1, R2) : std.range : isInputRange, Trait = std.traits
>> if (isInputRange!R1 && isInputRange!R2 && Trait.isArray!R2)
>> { ... }
December 14, 2016
On Wednesday, 14 December 2016 at 17:24:29 UTC, Anonymouse wrote:
> The with keyword then?
>
> bool equal(R1, R2)
> with (std.range : isInputRange, isOutputRange) && (std.stdio : writeln) && (std.algorithm)
> if (isInputRange!R1 && isInputRange!R2)
> { ... }

I guess the &&s there don't make sense. Maybe with a semicolon delimeter instead.

bool equal(R1, R2)
with (std.range : isInputRange, isOutputRange; std.stdio : writeln; std.algorithm)
if (isInputRange!R1 && isInputRange!R2)
{ ... }
December 14, 2016
On 12/14/2016 12:07 PM, David Gileadi wrote:
> The above rule doesn't cover non-template function declarations like the
> `process` example in the DIP, however. Are they an important enough use
> case to justify new syntax?

I suspect 90% of all uses will be straight definitions of template functions or template structs/classes. So by that estimate we should be in good shape.

However, looking inside the definition in order to look up names in its declarations breaks the rule of least astonishment. Making the import part of the syntactical unit of the declaration seems to be the path of least resistance.


Andrei

December 14, 2016
On 12/14/2016 12:24 PM, Anonymouse wrote:
> On Wednesday, 14 December 2016 at 17:09:44 UTC, ketmar wrote:
>> On Wednesday, 14 December 2016 at 17:01:50 UTC, Andrej Mitrovic
>>>
>>> How about:
>>>
>>> bool equal(R1, R2) : std.range
>>> if (isInputRange!R1 && isInputRange!R2)
>>> { ... }
>>>
>>> It's nice and concise, and you could in theory also allow multiple
>>> imports with a comma
>>>
>>> bool equal(R1, R2) : std.range, std.traits
>>> if (isInputRange!R1 && isInputRange!R2 && isArray!R2)
>>> { ... }
>>
>> breaks possible selective import. if both modules exports some symbol,
>> we will need to selectively import and/or rename it.
>
> The with keyword then?
>
> bool equal(R1, R2)
> with (std.range : isInputRange, isOutputRange) && (std.stdio : writeln)
> && (std.algorithm)
> if (isInputRange!R1 && isInputRange!R2)
> { ... }

The "import" keyword must be used. -- Andrei

December 14, 2016
On 12/14/2016 12:28 PM, Anonymouse wrote:
> On Wednesday, 14 December 2016 at 17:24:29 UTC, Anonymouse wrote:
>> The with keyword then?
>>
>> bool equal(R1, R2)
>> with (std.range : isInputRange, isOutputRange) && (std.stdio :
>> writeln) && (std.algorithm)
>> if (isInputRange!R1 && isInputRange!R2)
>> { ... }
>
> I guess the &&s there don't make sense. Maybe with a semicolon delimeter
> instead.
>
> bool equal(R1, R2)
> with (std.range : isInputRange, isOutputRange; std.stdio : writeln;
> std.algorithm)
> if (isInputRange!R1 && isInputRange!R2)
> { ... }

This would not pass either. -- Andrei
December 14, 2016
On Wed, Dec 14, 2016 at 05:24:42PM +0000, Andrej Mitrovic via Digitalmars-d wrote:
> On Wednesday, 14 December 2016 at 17:09:44 UTC, ketmar wrote:
> > > bool equal(R1, R2) : std.range, std.traits
> > > if (isInputRange!R1 && isInputRange!R2 && isArray!R2)
> > > { ... }
> > 
> > breaks possible selective import. if both modules exports some symbol, we will need to selectively import and/or rename it.
> 
> Not necessarily. The first colon is the only special case, afterwards you can use all forms of imports:
> 
> > > bool equal(R1, R2) : std.range : isInputRange, Trait = std.traits
> > > if (isInputRange!R1 && isInputRange!R2 && Trait.isArray!R2)
> > > { ... }

What about:

	/* Showing full declaration just for context */
	bool myFunc(R1, R2)(R1 r1, R2 r2)
	import {
		std.range : isInputRange,
		std.traits : isNum = isNumeric
	}
	if (isInputRange!R1 && isInputRange!R2 &&
	    isNum!(ElementType!R1))
	in { assert(someCondition!R1); }
	out(result) { assert(result == expectedResult(...)); }
	body
	{
		...
	}


T

-- 
EMACS = Extremely Massive And Cumbersome System
December 14, 2016
On Wednesday, 14 December 2016 at 17:24:42 UTC, Andrej Mitrovic wrote:
> On Wednesday, 14 December 2016 at 17:09:44 UTC, ketmar wrote:
>>> bool equal(R1, R2) : std.range, std.traits
>>> if (isInputRange!R1 && isInputRange!R2 && isArray!R2)
>>> { ... }
>>
>> breaks possible selective import. if both modules exports some symbol, we will need to selectively import and/or rename it.
>
> Not necessarily. The first colon is the only special case, afterwards you can use all forms of imports:
>
>>> bool equal(R1, R2) : std.range : isInputRange, Trait = std.traits
>>> if (isInputRange!R1 && isInputRange!R2 && Trait.isArray!R2)
>>> { ... }

i know that C school likes to add punctuation everywhere ;-), but i can't see why that is better than:

bool equal(R1, R2) import(std.range : isInputRange, Trait = std.traits) if ...

i think that the version with explicit keyword is easier to read.
December 14, 2016
On Wednesday, 14 December 2016 at 17:32:10 UTC, H. S. Teoh wrote:
> What about:
>
> 	/* Showing full declaration just for context */
> 	bool myFunc(R1, R2)(R1 r1, R2 r2)
> 	import {
> 		std.range : isInputRange,
> 		std.traits : isNum = isNumeric
> 	}
> 	if (isInputRange!R1 && isInputRange!R2 &&
> 	    isNum!(ElementType!R1))
> 	in { assert(someCondition!R1); }
> 	out(result) { assert(result == expectedResult(...)); }
> 	body
> 	{
> 		...
> 	}
>
>
> T

you won't stop me trying to write some code in import section then. hey, there are curly brackets, so it SHOULD accept code there! ;-)
December 14, 2016
On Wednesday, 14 December 2016 at 17:32:10 UTC, H. S. Teoh wrote:
> What about:
>
> 	/* Showing full declaration just for context */
> 	bool myFunc(R1, R2)(R1 r1, R2 r2)
> 	import {
> 		std.range : isInputRange,
> 		std.traits : isNum = isNumeric
> 	}
> 	if (isInputRange!R1 && isInputRange!R2 &&
> 	    isNum!(ElementType!R1))
> 	in { assert(someCondition!R1); }
> 	out(result) { assert(result == expectedResult(...)); }
> 	body
> 	{
> 		...
> 	}
>
>
> T

The fact that declarations like this WILL show up in Phobos or elsewhere if this proposal is implemented triggers my gag reflex. There's got to be a better way than tacking yet another pre-ambulatory clause to the function body.
December 14, 2016
What about simply this:


```
module foo;

{
import std.stdio;
void fun(File foo){}
}

{
import sd.range;
void foo(T) if(isInputRange!T){}
}

```



On Wed, Dec 14, 2016 at 9:50 AM, ketmar via Digitalmars-d < digitalmars-d@puremagic.com> wrote:

> On Wednesday, 14 December 2016 at 17:32:10 UTC, H. S. Teoh wrote:
>
>> What about:
>>
>>         /* Showing full declaration just for context */
>>         bool myFunc(R1, R2)(R1 r1, R2 r2)
>>         import {
>>                 std.range : isInputRange,
>>                 std.traits : isNum = isNumeric
>>         }
>>         if (isInputRange!R1 && isInputRange!R2 &&
>>             isNum!(ElementType!R1))
>>         in { assert(someCondition!R1); }
>>         out(result) { assert(result == expectedResult(...)); }
>>         body
>>         {
>>                 ...
>>         }
>>
>>
>> T
>>
>
> you won't stop me trying to write some code in import section then. hey, there are curly brackets, so it SHOULD accept code there! ;-)
>