syntax sugar: std.path::buildPath instead of from!"std.path".buildPath

Timothee Cour via Digitalmars-d digitalmars-d at puremagic.com
Mon Feb 13 22:39:31 PST 2017


`#std.stdio.File` doesn't work, we don't know where is the module
separator:
that could mean `module std` with a class stdio with a field File.

so the syntax would have be:

`std.stdio SYMBOL File`

frankly I don't care which symbol, so long it looks like that. And as I
said, `std.stdio::File` is reasonable since it's used for similar purpose
in rust and C++



On Mon, Feb 13, 2017 at 10:21 PM, Chris M via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On Tuesday, 14 February 2017 at 03:49:28 UTC, Timothee Cour wrote:
>
>> What about allowing syntax sugar as an alternative to relying on the new
>> `from/Module` inline import idiom:
>>
>> ```
>> void fun(T)(std.stdio::File input, T value) if (std.traits::isIntegral!T)
>> {...}
>> ```
>>
>> instead of:
>>
>> ```
>> void fun(T)(Module!"std.stdio".File input, T value) if
>> (Module!"std.traits".isIntegral!T) {...}
>> ```
>>
>> Rationale:
>>
>> * this reads much better (less noise); same as `=>` syntax for lambdas
>>
>> * this is expected to be a very common pattern, so might as well make it
>> as simple as possible
>>
>> * not particular on which symbol is used, could be something else, so
>> long it doesn't involve writing a string such as from!"std.traits". But ::
>> will be familiar to those coming from C++/rust etc.
>>
>> * from!"" is too loose and can be abused arbitrarily:
>>
>> ```
>> // this compiles
>> void fun(){
>>   from!"std.stdio; pragma(msg,`abuse...`); import std.stdio".File a;
>> }
>> ```
>>
>> Furthermore this is useful in other scenarios, namely when an import is
>> used only once in a context:
>> ```
>> auto fun(){  return std.file::getcwd; }
>> ```
>> is more DRY; instead of:
>> ```
>> auto fun(){ static import std.file;  return std.file.getcwd; }
>> auto fun(){ return Module!"std.file".getcwd; }
>> ```
>>
>> NOTE: if :: is not feasible for whatever reason, let's consider other
>> symbols without prejudice to this proposal.
>>
>
> Well, as Jack said there's no real clean way to do this without cluttering
> the function signatures more. However if this does happen through a
> language change, :: would look kind of awkward imo. I'd go with the
> following idea instead.
>
> void fun(T)(#std.stdio.File input, T value)
> if (#std.traits.isIntegral!T)
> {...}
>
> Doesn't necessarily have to be the octothorpe, but I think it looks a bit
> cleaner.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20170213/87306c08/attachment.html>


More information about the Digitalmars-d mailing list