July 26, 2021

On Saturday, 24 July 2021 at 17:52:03 UTC, Andrei Alexandrescu wrote:

>

On 7/23/21 5:15 PM, user1234 wrote:

>

On Friday, 23 July 2021 at 18:57:08 UTC, Steven Schveighoffer wrote:

>

On 7/23/21 9:55 AM, Andrei Alexandrescu wrote:

>

Mathias Lang just told me the bug preventing inline imports from working has been fixed, so I reopened this:

https://github.com/dlang/druntime/pull/1756

I think it's a very useful facility, more clearly so for large projects, and deserves a fair shake of the stick.

If it works well in practice, a future language proposal could take _import!"std.datetime".SysTime to the simpler and better import(std.datetime).SysTime. Using it as a library facility seems like a good step.

No comments on the inline-import mechanism. I'm not too concerned with the problem it solves (I'm OK adding imports when needed).

Just FYI, import(somefilenamestring) already is taken.

-Steve

It's possible to make the difference during semantic. If the expression between parens gives a StringExp -> ImportExpression, if that gives a ModuleDeclaration -> the new inline import.

Yah but that'd be awfully confusing...

I agree it could be confusing. That said I would really prefer if whatever we choose is an expression, as expressions are much easier to manipulate than statements via meta-programming - think of what you can put in an AliasSeq.
Even better, if can just use ranges to manipulate import lists. And no, stringly typed API is not the answer :D Perhaps something like a first-class Symbol type.

July 26, 2021
On 7/24/21 3:52 PM, qxi wrote:
> On Friday, 23 July 2021 at 13:55:34 UTC, Andrei Alexandrescu wrote:
>> Mathias Lang just told me the bug preventing inline imports from working has been fixed, so I reopened this:
>>
>> https://github.com/dlang/druntime/pull/1756
>>
>> I think it's a very useful facility, more clearly so for large projects, and deserves a fair shake of the stick.
>>
>> If it works well in practice, a future language proposal could take `_import!"std.datetime".SysTime` to the simpler and better `import(std.datetime).SysTime`. Using it as a library facility seems like a good step.
> 
> import[std.datetime].SysTime
> import{std.datetime}.SysTime
> import std.datetime..SysTime
> import std.datetime::SysTime
> std.datetime::SysTime

import:std.datetime.SysTime

July 26, 2021
On Monday, 26 July 2021 at 12:55:54 UTC, Andrei Alexandrescu wrote:
> On 7/24/21 3:52 PM, qxi wrote:
>> On Friday, 23 July 2021 at 13:55:34 UTC, Andrei Alexandrescu wrote:
>>> Mathias Lang just told me the bug preventing inline imports from working has been fixed, so I reopened this:
>>>
>>> https://github.com/dlang/druntime/pull/1756
>>>
>>> I think it's a very useful facility, more clearly so for large projects, and deserves a fair shake of the stick.
>>>
>>> If it works well in practice, a future language proposal could take `_import!"std.datetime".SysTime` to the simpler and better `import(std.datetime).SysTime`. Using it as a library facility seems like a good step.
>> 
>> import[std.datetime].SysTime
>> import{std.datetime}.SysTime
>> import std.datetime..SysTime
>> import std.datetime::SysTime
>> std.datetime::SysTime
>
> import:std.datetime.SysTime

Problem with 'import:std.datetime.SysTime' is that we cant tell which identifier is imported symbol (unless we assume that the last identifier is an imported symbol),
for example 'import:A.B.C' we dont know we import symbol 'B' from module 'A' or symbol 'C' from module 'A.B', with may both exists.

Examples that dont work:

import:Module.Struct.StaticFunction(arguments)
import:Module.AliasToTplInst.SomeType

I know it is possible to write '(import:Module.Struct).StaticFunction(arguments)' but that dont look right (at least for me), and in my examples using brackets or tokens is to easier distinguish module name from imported symbol (in all cases).



July 27, 2021
On 26.07.21 14:55, Andrei Alexandrescu wrote:
> On 7/24/21 3:52 PM, qxi wrote:
[...]
>> import[std.datetime].SysTime
>> import{std.datetime}.SysTime
>> import std.datetime..SysTime
>> import std.datetime::SysTime
>> std.datetime::SysTime
> 
> import:std.datetime.SysTime

module(std.datetime).SysTime
July 27, 2021
On Monday, 26 July 2021 at 12:55:54 UTC, Andrei Alexandrescu wrote:
>> import[std.datetime].SysTime
>> import{std.datetime}.SysTime
>> import std.datetime..SysTime
>> import std.datetime::SysTime
>> std.datetime::SysTime
>
> import:std.datetime.SysTime

import.std.datetime.SysTime

Not sure if it needs to provide access to deeply nested symbols. In that case you can just formulate module lookup rules.
July 27, 2021
On Tuesday, 27 July 2021 at 05:07:32 UTC, ag0aep6g wrote:
> On 26.07.21 14:55, Andrei Alexandrescu wrote:
>> On 7/24/21 3:52 PM, qxi wrote:
> [...]
>>> import[std.datetime].SysTime
>>> import{std.datetime}.SysTime
>>> import std.datetime..SysTime
>>> import std.datetime::SysTime
>>> std.datetime::SysTime
>> 
>> import:std.datetime.SysTime
>
> module(std.datetime).SysTime

That's the best suggestion so far.
July 27, 2021
On Tuesday, 27 July 2021 at 09:20:25 UTC, Petar Kirov [ZombineDev] wrote:
> On Tuesday, 27 July 2021 at 05:07:32 UTC, ag0aep6g wrote:
>> On 26.07.21 14:55, Andrei Alexandrescu wrote:
>>> On 7/24/21 3:52 PM, qxi wrote:
>> [...]

>> module(std.datetime).SysTime
>
> That's the best suggestion so far.

I agree. But how about, for the sake of consistency (but at the cost of some verbosity):

import module(std.datetime).SysTime
July 27, 2021
On Tuesday, 27 July 2021 at 09:48:03 UTC, ShadoLight wrote:
> On Tuesday, 27 July 2021 at 09:20:25 UTC, Petar Kirov [ZombineDev] wrote:
>> On Tuesday, 27 July 2021 at 05:07:32 UTC, ag0aep6g wrote:
>>> On 26.07.21 14:55, Andrei Alexandrescu wrote:
>>>> On 7/24/21 3:52 PM, qxi wrote:
>>> [...]
>
>>> module(std.datetime).SysTime
>>
>> That's the best suggestion so far.
>
> I agree. But how about, for the sake of consistency (but at the cost of some verbosity):
>
> import module(std.datetime).SysTime

How is that more consistent?
July 27, 2021
On Tuesday, 27 July 2021 at 10:55:48 UTC, deadalnix wrote:
> On Tuesday, 27 July 2021 at 09:48:03 UTC, ShadoLight wrote:
>> On Tuesday, 27 July 2021 at 09:20:25 UTC, Petar Kirov [ZombineDev] wrote:
>>> On Tuesday, 27 July 2021 at 05:07:32 UTC, ag0aep6g wrote:
>>>> On 26.07.21 14:55, Andrei Alexandrescu wrote:
>>>>> On 7/24/21 3:52 PM, qxi wrote:
>>>> [...]
>>
>>>> module(std.datetime).SysTime
>>>
>>> That's the best suggestion so far.
>>
>> I agree. But how about, for the sake of consistency (but at the cost of some verbosity):
>>
>> import module(std.datetime).SysTime
>
> How is that more consistent?

Oh s**t, you are right; I've forgotten that this was for only for inline declarations... ok, scratch that idea. Adding 'import' would not only _not be_ consistent, but will look really weird.

July 27, 2021
On Tuesday, 27 July 2021 at 09:20:25 UTC, Petar Kirov [ZombineDev] wrote:
> On Tuesday, 27 July 2021 at 05:07:32 UTC, ag0aep6g wrote:
>> On 26.07.21 14:55, Andrei Alexandrescu wrote:
>>> On 7/24/21 3:52 PM, qxi wrote:
>> [...]
>>>> import[std.datetime].SysTime
>>>> import{std.datetime}.SysTime
>>>> import std.datetime..SysTime
>>>> import std.datetime::SysTime
>>>> std.datetime::SysTime
>>> 
>>> import:std.datetime.SysTime
>>
>> module(std.datetime).SysTime
>
> That's the best suggestion so far.

1) std.datetime::SysTime
2) module(std.datetime).SysTime

From a human readability perspective I like option (1) the best, however from a compiler perspective, you cannot tell that LHS is a module until it sees the final ::(or some other operator), that might not be optimal.

Overall, I also think option 2 is the most realistic compromise.