Jump to page: 1 25  
Page
Thread overview
First life-signs of type functions
May 06, 2020
Stefan Koch
May 06, 2020
Stefan Koch
May 09, 2020
Stefan Koch
May 10, 2020
Nick Treleaven
May 10, 2020
Nick Treleaven
May 10, 2020
Stefan Koch
May 10, 2020
Stefan Koch
May 10, 2020
Nick Treleaven
May 11, 2020
Q. Schroll
May 11, 2020
Stefan Koch
May 12, 2020
Stefan Koch
May 12, 2020
Johannes Loher
May 12, 2020
Stefan Koch
May 12, 2020
Max Samukha
May 12, 2020
Stefan Koch
May 12, 2020
Stefan Koch
May 12, 2020
Johannes Loher
May 12, 2020
Stefan Koch
May 12, 2020
Max Samukha
May 12, 2020
Johannes Loher
May 30, 2020
Nick Treleaven
May 30, 2020
Stefan Koch
May 13, 2020
Nick Treleaven
May 14, 2020
Stefan Koch
May 18, 2020
Timon Gehr
May 10, 2020
Stefan Koch
May 10, 2020
Patrick Schluter
May 10, 2020
Stefan Koch
May 10, 2020
Stefan Koch
May 10, 2020
Nick Treleaven
May 19, 2020
Stefan Koch
May 19, 2020
Stefan Koch
May 27, 2020
Stefan Koch
May 28, 2020
Seb
May 12, 2020
Stefan Koch
May 13, 2020
Clueless
May 13, 2020
Stefan Koch
May 06, 2020
Hello Guys,

After a bit of fiddling the following code (and only that because I need do partial evaluation of the semantic pass on the function body manually ...)
Now works on the Talias branch

string F(alias y)
{
    return y.stringof;
}
static assert(F!(ulong) == "ulong");
static assert(F!(uint) == "uint");

May 06, 2020
On Wednesday, 6 May 2020 at 11:58:36 UTC, Stefan Koch wrote:
> Now works on the Talias branch
>

https://github.com/dlang/dmd/compare/master...UplinkCoder:talias?expand=1

As you can see the modifications aren't even that heavy.
I am confident this will take significantly less time than re-implementing CTFE.
Because it's a new feature and bugs can be fixed as they are discovered.
May 09, 2020
On Wednesday, 6 May 2020 at 12:01:11 UTC, Stefan Koch wrote:
> On Wednesday, 6 May 2020 at 11:58:36 UTC, Stefan Koch wrote:
>> Now works on the Talias branch
>>
>
> https://github.com/dlang/dmd/compare/master...UplinkCoder:talias?expand=1
>
> As you can see the modifications aren't even that heavy.
> I am confident this will take significantly less time than re-implementing CTFE.
> Because it's a new feature and bugs can be fixed as they are discovered.

As of a few minutes ago the following code compiles without errors!

string fqn(alias t)
{
    string result = t.stringof;
    alias p;
    p = t;
    bool good = is(typeof(__traits(parent, p)));
    while(good)
    {
        p = __traits(parent, p);
        result = p.stringof ~ "." ~ result;
//        result = __traits(identifier, parent) ~ "." ~ result;
        good = is(typeof(__traits(parent, p)));

    }

    return cast(string) result;
}

struct S
{
    struct X
    {
        int xx;
        static assert( fqn!xx == "module " ~ __MODULE__ ~ ".S.X.xx" );
    }
}

May 10, 2020
On Saturday, 9 May 2020 at 06:39:20 UTC, Stefan Koch wrote:
>     alias p;
>     p = t;
>     bool good = is(typeof(__traits(parent, p)));
>     while(good)
>     {
>         p = __traits(parent, p);
>         result = p.stringof ~ "." ~ result;
> //        result = __traits(identifier, parent) ~ "." ~ result;
>         good = is(typeof(__traits(parent, p)));
>     }

Very cool!

When `alias[]` is implemented, would this work:

bool anySatisfy(alias Tem, alias[] S)
{
    bool found;
    alias E;
    while (S.length)
    {
        E = S[0];
        if (Tem!E)
            return true;
        S = S[1..$];
    }
    return false;
}

enum isPointer(T) = is(T : E*, E);
pragma(msg, anySatisfy!(isPointer, int, char, void, int*, byte));

Any idea how fast this would be compared to `core.internal.traits : anySatisfy` (which doesn't use template recursion)?
May 10, 2020
On Saturday, 9 May 2020 at 06:39:20 UTC, Stefan Koch wrote:
> On Wednesday, 6 May 2020 at 12:01:11 UTC, Stefan Koch wrote:
>> On Wednesday, 6 May 2020 at 11:58:36 UTC, Stefan Koch wrote:
>>> Now works on the Talias branch
>>>
>>
>> https://github.com/dlang/dmd/compare/master...UplinkCoder:talias?expand=1
>>
>> As you can see the modifications aren't even that heavy.
>> I am confident this will take significantly less time than re-implementing CTFE.
>> Because it's a new feature and bugs can be fixed as they are discovered.
>
> As of a few minutes ago the following code compiles without errors!
>
> string fqn(alias t)
> {
>     string result = t.stringof;
>     alias p;
>     p = t;
>     bool good = is(typeof(__traits(parent, p)));
>     while(good)
>     {
>         p = __traits(parent, p);
>         result = p.stringof ~ "." ~ result;
> //        result = __traits(identifier, parent) ~ "." ~ result;
>         good = is(typeof(__traits(parent, p)));
>
>     }
>
>     return cast(string) result;
> }
>
> struct S
> {
>     struct X
>     {
>         int xx;
>         static assert( fqn!xx == "module " ~ __MODULE__ ~ ".S.X.xx" );
>     }
> }

__traits(identifier) works now making the code a little bit nicer.

string fqn(alias t)
{
    string result = t.stringof;
    alias p;
    p = t;
    bool good = is(typeof(__traits(parent, p)));

    while(good)
    {
        p = __traits(parent, p);
        result = __traits(identifier, p) ~ "." ~ result;
        good = is(typeof(__traits(parent, p)));

    }

    return result;
}

struct S
{
    struct X
    {
        int xx;
        static assert( fqn!xx == __MODULE__ ~ ".S.X.xx" );
    }
}

I am not super happy with how this looks ... especially that I am getting __traits(parent) twice. If anyone has a suggestion of how to write this better.
Please tell me :)

Also I am documenting the process of implementing this on my youtube channel (https://www.youtube.com/channel/UCdZpjZcilNRQH2GDY-P5yVA) (whenever I remember to press record and having something interesting to show)

May 10, 2020
On Sunday, 10 May 2020 at 08:43:42 UTC, Stefan Koch wrote:
> On Saturday, 9 May 2020 at 06:39:20 UTC, Stefan Koch wrote:
>> [...]
>
> __traits(identifier) works now making the code a little bit nicer.
>
> [...]

Would have been nice to have that video in a better quality than 360p. The text is completely unreadable.
May 10, 2020
On Sunday, 10 May 2020 at 09:33:29 UTC, Patrick Schluter wrote:
> On Sunday, 10 May 2020 at 08:43:42 UTC, Stefan Koch wrote:
>> On Saturday, 9 May 2020 at 06:39:20 UTC, Stefan Koch wrote:
>>> [...]
>>
>> __traits(identifier) works now making the code a little bit nicer.
>>
>> [...]
>
> Would have been nice to have that video in a better quality than 360p. The text is completely unreadable.

Oh yes I just realized that.
Let me to a reupload ... youtube seems to have problems.
May 10, 2020
On Sunday, 10 May 2020 at 09:35:18 UTC, Stefan Koch wrote:
> On Sunday, 10 May 2020 at 09:33:29 UTC, Patrick Schluter wrote:
>> On Sunday, 10 May 2020 at 08:43:42 UTC, Stefan Koch wrote:
>>> On Saturday, 9 May 2020 at 06:39:20 UTC, Stefan Koch wrote:
>>>> [...]
>>>
>>> __traits(identifier) works now making the code a little bit nicer.
>>>
>>> [...]
>>
>> Would have been nice to have that video in a better quality than 360p. The text is completely unreadable.
>
> Oh yes I just realized that.
> Let me to a reupload ... youtube seems to have problems.

youtube changed to only showing SD content it seems like?
Because of covid-19 ... this is crazy.
May 10, 2020
On Sunday, 10 May 2020 at 08:39:42 UTC, Nick Treleaven wrote:
>     alias E;
>     while (S.length)
>     {
>         E = S[0];
>         if (Tem!E)
>             return true;
>         S = S[1..$];
>     }
>     return false;

I had assumed that indexing an alias[] with a mutable variable wouldn't work. If it does, then I don't even need to mutate S:

bool anySatisfy(alias Tem, alias[] S)
{
    size_t i = 0;
    while (i != S.length)
    {
        if (Tem!(S[i]))
            return true;
        i++;
    }
    return false;
}

May 10, 2020
On Sunday, 10 May 2020 at 10:28:17 UTC, Nick Treleaven wrote:
> On Sunday, 10 May 2020 at 08:39:42 UTC, Nick Treleaven wrote:
>>     alias E;
>>     while (S.length)
>>     {
>>         E = S[0];
>>         if (Tem!E)
>>             return true;
>>         S = S[1..$];
>>     }
>>     return false;
>
> I had assumed that indexing an alias[] with a mutable variable wouldn't work. If it does, then I don't even need to mutate S:
>
> bool anySatisfy(alias Tem, alias[] S)
> {
>     size_t i = 0;
>     while (i != S.length)
>     {
>         if (Tem!(S[i]))
>             return true;
>         i++;
>     }
>     return false;
> }

I've posted the simplest version in the other thread.
this version can still lose a few lines :)
« First   ‹ Prev
1 2 3 4 5