syntax sugar: std.path::buildPath instead of from!"std.path".buildPath
Nick Treleaven via Digitalmars-d
digitalmars-d at puremagic.com
Tue Feb 21 08:04:27 PST 2017
On Sunday, 19 February 2017 at 01:53:58 UTC, Timothee Cour wrote:
>> Doesn't add indentation:
>>
>> with (module_!"std.stdio, std.traits")
>> void fun(T)(File input, T value)
>> if (isIntegral!T);
>
> * what is the implementation of `module_` ? `from` defined
> earlier doesn't allow for multiple modules as in
> from!"std.stdio, std.traits"`. But let's assume it can be done
> for now.
I don't know how to implement it. Possibly with multiple alias
this.
> * when `with` covers multiple declarations, it adds indentation:
> with(module_!"std.stdio"){
> declaration1;
> declaration2;
> }
>
> * when `with` covers a single one, it doesn't add indentation,
> but then `::` can be used instead, with arguably simpler syntax:
>
> `void fun(T)(std.stdio::File input, T value);`
> vs
> `with (module_!"std.stdio") void fun(T)(File input, T value);`
What about when the 2nd argument uses File as well? That's the
violation of DRY I meant.
>> with/module_ solves the UFCS member stand-in problem
>> elegantly, how does your proposal solve it?:
>> with (module_!"std.range.primitives")
>> void func(alias pred, R)(R range)
>> if (isInputRange!R && is(typeof(pred(range.front)) == bool);
>>
>> .front has to refer to *either* a member or an imported UFCS
>> function.
>
> UFCS equally affects the `::` proposal and the
> `module_!""`-without-`with` proposal.
>
> Besides the option of not using UFCS, we can actually use Alias
> for
> this, as I've proposed a while ago in
> http://forum.dlang.org/post/mailman.1002.1370829729.13711.digitalmars-d-learn@puremagic.com:
>
> `with (module_!"std.range.primitives") ... pred(range.front)`
> vs:
> `... pred(range.Alias!(std.range.primitives::front))`
>
> or, if a feature that I've proposed earlier in
> http://forum.dlang.org/post/mailman.1453.1369099708.4724.digitalmars-d@puremagic.com
> (support UFCS with fully qualified function names) is accepted,
> it
> becomes even simpler:
>
> `... pred(range.(std.range.primitives::front))`
No, then front only refers to the std.range one, not R.front if
it exists. The with() solution is like a lazy scoped import,
affecting overloading, whereas using just from! or mod:: forces a
lookup in that module scope only.
More information about the Digitalmars-d
mailing list