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

ZombineDev via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 16 01:38:07 PST 2017


On Thursday, 16 February 2017 at 00:40:19 UTC, John Colvin wrote:
> On Wednesday, 15 February 2017 at 19:39:52 UTC, Andrei 
> Alexandrescu wrote:
>> On 02/15/2017 06:20 AM, Daniel N wrote:
>>> On Wednesday, 15 February 2017 at 09:22:14 UTC, Daniel N 
>>> wrote:
>>>> template every(T...)
>>>> {
>>>>     template satisfies(U...)
>>>>     {
>>>>         enum satisfies = true;
>>>>     }
>>>> }
>>>
>>> (lunch-break => time to hack D!)
>>>
>>> template every(T...)
>>> {
>>>   template satisfies(U...)
>>>   {
>>>     enum satisfies = {
>>>       foreach(t; T)
>>>         foreach(u; U)
>>>       if(!u!t)
>>>             return false;
>>>       return true;
>>>     }();
>>>   }
>>> }
>>
>> That looks pretty neat. Can you find 4-5 cases in which this 
>> could be used gainfully in Phobos? Thanks! -- Andrei
>
> Slightly OT, but it is related so bear with me:
>
> Design by introspection is great and prevent having to make new 
> names for every possible combo of features. Unfortunately, it 
> doesn't work so well for introspecting multiple types at once: 
> normally you have to then make a new symbol, with a new name, 
> to pass to e.g. allSatisfy. That annoys me, so I've been 
> wanting this sort of thing for a while (which would also make 
> `every` way better to use, instead of having to make a name for 
> every predicate:
>
> You know how we have named parameterised enums and aliases?
> enum isInt(a) = is(a == int);
> and
> alias sizeof(a) = a.sizeof;
>
> why not allow *anonymous* parameterised enums and aliases, like 
> this:
>
> enum areAllInt(TL ...) = allSatisfy!(enum(a) => is(a == int), 
> TL);
>
> void foo(TL...)(TL args)
> if (allSatisfy!(enum(T) => T.sizeof <= 4, TL))
> {
>     // ...
> }
>
> [snip]
>

I have a library that allows just that, but with even shorter 
syntax :P

https://github.com/ZombineDev/rxd/blob/v0.0.3/source/rxd/xf/xform.d#L50
https://github.com/ZombineDev/rxd/blob/v0.0.3/source/rxd/meta2/type.d#L241

Though I have feeling that it will make uplinkCoder cringe, 
because of the pressure it is probably putting on the compiler :D


More information about the Digitalmars-d mailing list