May 06, 2020 First life-signs of type functions | ||||
---|---|---|---|---|
| ||||
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 Re: First life-signs of type functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | 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 Re: First life-signs of type functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | 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 Re: First life-signs of type functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | 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 Re: First life-signs of type functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | 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 Re: First life-signs of type functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | 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 Re: First life-signs of type functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Patrick Schluter | 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 Re: First life-signs of type functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | 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 Re: First life-signs of type functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | 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 Re: First life-signs of type functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | 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 :)
|
Copyright © 1999-2021 by the D Language Foundation