December 14, 2016 Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wednesday, 14 December 2016 at 01:39:01 UTC, Andrei Alexandrescu wrote:
> On 12/13/16 8:07 PM, Chris M. wrote:
>> [...]
>
> So we have:
>
> // 1
> struct Buffer(R) if ((import std.range).isInputRange!R) { ... }
>
> [...]
What about?:
with(import std.range)
bool equal(R1, R2) if (isInputRange!R1 && isInputRange!R2)
{ ... }
|
December 13, 2016 Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris M. | On 12/13/16 8:53 PM, Chris M. wrote:
> On Wednesday, 14 December 2016 at 01:39:01 UTC, Andrei Alexandrescu wrote:
>
>> I prefer the current form of the proposal:
>>
>> bool equal(R1, R2)
>> import (std.range)
>> if (isInputRange!R1 && isInputRange!R2)
>> { ... }
>>
>> The point has been brought up that the syntax import(std.range) is
>> also used for string imports. It is a drawback.
>>
>>
>> Andrei
>
> How about using "imports" instead of "import"? Simple enough change, and
> it still makes sense
>
> bool equal(R1, R2)
> imports (std.range)
> if (isInputRange!R1 && isInputRange!R2)
> { ... }
I fear that (a) a lot of folks will believe "imports" is a keyword; (b) another lot of folks will write "import" instead of "imports" and wonder why it doesn't work. -- Andrei
|
December 13, 2016 Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hatem Oraby | On 12/13/16 9:22 PM, Hatem Oraby wrote:
> On Wednesday, 14 December 2016 at 01:39:01 UTC, Andrei Alexandrescu wrote:
>> On 12/13/16 8:07 PM, Chris M. wrote:
>>> [...]
>>
>> So we have:
>>
>> // 1
>> struct Buffer(R) if ((import std.range).isInputRange!R) { ... }
>>
>> [...]
>
> What about?:
>
> with(import std.range)
> bool equal(R1, R2) if (isInputRange!R1 && isInputRange!R2)
> { ... }
I considered this, then figured with is superfluous. -- Andrei
|
December 14, 2016 Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wednesday, 14 December 2016 at 02:23:07 UTC, Andrei Alexandrescu wrote:
> On 12/13/16 8:53 PM, Chris M. wrote:
>> On Wednesday, 14 December 2016 at 01:39:01 UTC, Andrei Alexandrescu wrote:
>>
>>> I prefer the current form of the proposal:
>>>
>>> bool equal(R1, R2)
>>> import (std.range)
>>> if (isInputRange!R1 && isInputRange!R2)
>>> { ... }
>>>
>>> The point has been brought up that the syntax import(std.range) is
>>> also used for string imports. It is a drawback.
>>>
>>>
>>> Andrei
>>
>> How about using "imports" instead of "import"? Simple enough change, and
>> it still makes sense
>>
>> bool equal(R1, R2)
>> imports (std.range)
>> if (isInputRange!R1 && isInputRange!R2)
>> { ... }
>
> I fear that (a) a lot of folks will believe "imports" is a keyword; (b) another lot of folks will write "import" instead of "imports" and wonder why it doesn't work. -- Andrei
Could use something like "using" or "with" instead of "import" then.
bool equal(R1, R2)
using(std.range)
if (isInputRange!R1 && isInputRange!R2)
{ ... }
Of course, the collision with the syntax for string imports might not be a huge deal anyway, since you could easily distinguish between when it's for a string import and when it's for a inline import just by the context you see it in. Leaving it as "import" would probably be fine too.
|
December 14, 2016 Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wednesday, 14 December 2016 at 01:39:01 UTC, Andrei Alexandrescu wrote: > I prefer the current form of the proposal: > > bool equal(R1, R2) > import (std.range) > if (isInputRange!R1 && isInputRange!R2) > { ... } > I didn't see an example of the syntax when multiple imports are involved (apologies if I missed it). Would be good to spell it out. For example, the start to uninitializedArray (array.d): auto uninitializedArray(T, I...)(I sizes) nothrow @system if (isDynamicArray!T && allSatisfy!(isIntegral, I) && hasIndirections!(ElementEncodingType!T)) { This uses imports from std.traits, std.meta, and std.range. Would there be one import statement or three? I'm guessing so the intent is one, so perhaps: auto uninitializedArray(T, I...)(I sizes) nothrow @system import (std.traits; std.meta; std.range) if (isDynamicArray!T && allSatisfy!(isIntegral, I) && hasIndirections!(ElementEncodingType!T)) { Is that the idea? Similarly for importing individual symbols. In the above case: auto uninitializedArray(T, I...)(I sizes) nothrow @system import (std.traits : hasIndirections, isDynamicArray, isIntegral; std.meta : allSatisfy; std.range : ElementEncodingType) if (isDynamicArray!T && allSatisfy!(isIntegral, I) && hasIndirections!(ElementEncodingType!T)) { --Jon |
December 14, 2016 Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Tuesday, 13 December 2016 at 22:33:24 UTC, Andrei Alexandrescu wrote:
> Destroy.
>
> https://github.com/dlang/DIPs/pull/51/files
Imho such syntaxis construction make language harder to learn. D is already pretty complex, but DIPs should simplify language, but do not make its harder
|
December 14, 2016 Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 2016-12-14 03:23, Andrei Alexandrescu wrote: > On 12/13/16 9:22 PM, Hatem Oraby wrote: >> with(import std.range) >> bool equal(R1, R2) if (isInputRange!R1 && isInputRange!R2) >> { ... } > > I considered this, then figured with is superfluous. -- Andrei It could allow to have a better control of the scope which the import affects, i.e.: with(import std.range) { void foo(T) if (isInputRange!T) void bar(T) if (isInputRange!T) } -- /Jacob Carlborg |
December 14, 2016 Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Wednesday, 14 December 2016 at 07:17:57 UTC, Jacob Carlborg wrote:
> On 2016-12-14 03:23, Andrei Alexandrescu wrote:
>> On 12/13/16 9:22 PM, Hatem Oraby wrote:
>
>>> with(import std.range)
>>> bool equal(R1, R2) if (isInputRange!R1 && isInputRange!R2)
>>> { ... }
>>
>> I considered this, then figured with is superfluous. -- Andrei
>
> It could allow to have a better control of the scope which the import affects, i.e.:
>
> with(import std.range)
> {
> void foo(T) if (isInputRange!T)
> void bar(T) if (isInputRange!T)
> }
Look very nice!
|
December 14, 2016 Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Tuesday, 13 December 2016 at 22:33:24 UTC, Andrei Alexandrescu wrote:
> Destroy.
>
> https://github.com/dlang/DIPs/pull/51/files
>
>
> Andrei
Proposed functionality does feel useful but syntax options mentioned in the DIP all seem lacking to me. Most importantly, the one suggested as primary option puts import after the symbol in lexical order which looks baroque and may even be unprecedented in the language (can't think of another case like that immediately).
|
December 14, 2016 Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Wednesday, 14 December 2016 at 08:16:56 UTC, Suliman wrote:
> On Wednesday, 14 December 2016 at 07:17:57 UTC, Jacob Carlborg wrote:
>> On 2016-12-14 03:23, Andrei Alexandrescu wrote:
>>> On 12/13/16 9:22 PM, Hatem Oraby wrote:
>>
>>>> with(import std.range)
>>>> bool equal(R1, R2) if (isInputRange!R1 && isInputRange!R2)
>>>> { ... }
>>>
>>> I considered this, then figured with is superfluous. -- Andrei
>>
>> It could allow to have a better control of the scope which the import affects, i.e.:
>>
>> with(import std.range)
>> {
>> void foo(T) if (isInputRange!T)
>> void bar(T) if (isInputRange!T)
>> }
>
> Look very nice!
If this looks nice to you then I would like to propose:
@import("std.range"):
void foo(T) if (isInputRange!T)
And:
@import("std.range")
{
void foo(T) if (isInputRange!T)
void bar(T) if (isInputRange!T)
}
In my eye this whole thing fits really well into the property syntax. Yes, it's a little strange to pass module name as string. Otherwise it's perfect.
Maybe we can allow properties to take symbol as argument?
|
Copyright © 1999-2021 by the D Language Foundation