Inline imports redivivus
Ali Çehreli
acehreli at yahoo.com
Mon Mar 7 18:45:54 UTC 2022
On 3/7/22 02:27, Per Nordlöw wrote:
> https://forum.dlang.org/post/sdehom$10fi$1@digitalmars.com
>
> On Friday, 23 July 2021 at 13:55:34 UTC, Andrei Alexandrescu wrote:
>
>> 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`.
>
> Yes, please!
This seems to be yet another example of the need for template string
arguments typed as symbols in the source code.
- Flag!"foo" could become Flag(foo) (or more consistently Flag!foo).
- bitfields could become bitfields!(int, x, 8) instead of
bitfields!(int, "x", 8)[*]
Andrei mentioned a couple of times that this is what was discussed as
"new alias" in the past where the template allows the use of an
"unknown" (or "new") symbol at call site. I see a strong similarity here
to the existing opDispatch() that makes compile-time strings from
"unknown" symbols at call site.
Ali
[*] I think it would be interesting to come up with a language solution
that would e.g. enable combining each three consecutive arguments of
bitfields. It is a code smell that everybody knows that the three
separate arguments go together but we don't use a language construct for
that. We already have the following method in the current language but
it is obviously redundant and perhaps that's why the current design of
bitfields does not use it:
bitfields!(Bit(int, x, 8), // Better but redundant
Bit(int, y, 8));
A solution that would allow the following would be interesting:
bitfields!(int x : 8,
int y : 8);
So, we somehow specify at template definition that two (or three?)
parameters (e.g. int and x) can be specified without a comma and perhaps
anything after ':' are UDAs of that parameter?
More information about the Digitalmars-d
mailing list