Jump to page: 1 2
Thread overview
Template declaration of std.typecons.isTuple in -X JSON file.
5 days ago
realhet
5 days ago
monkyyy
5 days ago
realhet
5 days ago
realhet
5 days ago
monkyyy
5 days ago
monkyyy
5 days ago
realhet
5 days ago
monkyyy
5 days ago
realhet
5 days ago

Hello,

I'm working on understanding and automating the contents of an X Json file generated by LDC2.
I'm testing it by processing the whole Phobos lib.

The weirdest thing that I've found is this:
X Json:


With my program, I transformed into this header source code:

public template isTuple(T) {enum isTuple = __traits(compiles, ()
{
template f(Specs...)f(T.init);
}
);}

Then the parser in my custom IDE was stopped with error: It can't handle template with the ';' ending.
So I temporarily enabled that form, but I can't find that template; form in the documentation. I only found info about template{}.

Later I've found that the "template f(Specs...)f(T.init);" thing is also in the DDoc of the std.typecons.d module.

enum isTuple(T) = __traits(compiles, () { template f(Specs...)f(T.init); } );

(It's just embedded code in the json as a string. So it was the same at me as well.)

Anyone can explain me what

template f(Specs...)f(T.init);

means?

From now on, I will detect it as valid, but please help me understand it.

Thx in advance!

5 days ago

On Wednesday, 15 January 2025 at 12:01:21 UTC, realhet wrote:

>

Hello,

I'm working on understanding and automating the contents of an X Json file generated by LDC2.
I'm testing it by processing the whole Phobos lib.

The weirdest thing that I've found is this:
X Json:


With my program, I transformed into this header source code:

public template isTuple(T) {enum isTuple = __traits(compiles, ()
{
template f(Specs...)f(T.init);
}
);}

Then the parser in my custom IDE was stopped with error: It can't handle template with the ';' ending.
So I temporarily enabled that form, but I can't find that template; form in the documentation. I only found info about template{}.

Later I've found that the "template f(Specs...)f(T.init);" thing is also in the DDoc of the std.typecons.d module.

enum isTuple(T) = __traits(compiles, () { template f(Specs...)f(T.init); } );

(It's just embedded code in the json as a string. So it was the same at me as well.)

Anyone can explain me what

template f(Specs...)f(T.init);

means?

From now on, I will detect it as valid, but please help me understand it.

Thx in advance!

the defination of aliasSeq is alias seq(T...)=T; my defination of tuple is

struct Tuple(T...){
  T expand;alias expand this;
}

to define templates you reuse the name to "return"; I cant spell remotely spell the term form the spec

template foo(){
  enum foo=1;
}
assert(foo!()=1);

all together that looks like they define a tuple inline and return its init which I think is probably expanding in some strange way

5 days ago

When I write:

template f(Specs...)f(T.init);

The compiler syntactically refuses it: It expects a '{', not a "f".

Why they use this inside a __traits(compiles, {}) in Phobos? Does it makes sense inside there?

5 days ago
struct Tuple(T...){ T expand;alias expand this; }

pragma(msg, isTuple!(Tuple!(int)));

And LDC2's opinion about Your Tuple is: Not a tuple :D

These are the mysterious parts of the language, I like this stuff, even I can't understand.

5 days ago

On Wednesday, 15 January 2025 at 12:01:21 UTC, realhet wrote:

>

Hello,

I'm working on understanding and automating the contents of an X Json file generated by LDC2.
I'm testing it by processing the whole Phobos lib.

The weirdest thing that I've found is this:
X Json:


Is there something missing here? Hard to understand the rest without it.

>

With my program, I transformed into this header source code:

public template isTuple(T) {enum isTuple = __traits(compiles, ()
{
template f(Specs...)f(T.init);
}
);}

Then the parser in my custom IDE was stopped with error: It can't handle template with the ';' ending.
So I temporarily enabled that form, but I can't find that template; form in the documentation. I only found info about template{}.

That is not valid syntax AFAIK.

>

Later I've found that the "template f(Specs...)f(T.init);" thing is also in the DDoc of the std.typecons.d module.

enum isTuple(T) = __traits(compiles, () { template f(Specs...)f(T.init); } );

(It's just embedded code in the json as a string. So it was the same at me as well.)

Also seems like invalid syntax. Where does this come from?

>

Anyone can explain me what

template f(Specs...)f(T.init);

means?

I think it's meant to be a documentation thing, or AST printout (which isn't always valid syntax)? It's not valid declaration syntax, template requires {}.

-Steve

5 days ago

On Wednesday, 15 January 2025 at 20:27:18 UTC, Steven Schveighoffer wrote:

>

On Wednesday, 15 January 2025 at 12:01:21 UTC, realhet wrote:

>

Also seems like invalid syntax. Where does this come from?

It's in std.typecons.d -> git link

It's in the declaration of enum isTuple(T) = ....

5 days ago

On Wednesday, 15 January 2025 at 20:06:19 UTC, realhet wrote:

>

These are the mysterious parts of the language, I like this stuff, even I can't understand.

it should also be noted that trait compiles is not actually a compile check, its more like "parses"

5 days ago
On 16/01/2025 10:36 AM, monkyyy wrote:
> On Wednesday, 15 January 2025 at 20:06:19 UTC, realhet wrote:
>>
>> These are the mysterious parts of the language, I like this stuff, even I can't understand.
> 
> it should also be noted that trait compiles is not actually a compile check, its more like "parses"

It does do semantic analysis, if it passes, it should compile fully (note it may not link or run on target hardware).

https://github.com/dlang/dmd/blob/ace0e6329521819d8fe51e42ae37a23782f25707/compiler/src/dmd/traits.d#L1826

5 days ago
On Wednesday, 15 January 2025 at 21:40:19 UTC, Richard (Rikki) Andrew Cattermole wrote:
> On 16/01/2025 10:36 AM, monkyyy wrote:
>> On Wednesday, 15 January 2025 at 20:06:19 UTC, realhet wrote:
>>>
>>> These are the mysterious parts of the language, I like this stuff, even I can't understand.
>> 
>> it should also be noted that trait compiles is not actually a compile check, its more like "parses"
>
> It does do semantic analysis, if it passes, it should compile fully (note it may not link or run on target hardware).
>
> https://github.com/dlang/dmd/blob/ace0e6329521819d8fe51e42ae37a23782f25707/compiler/src/dmd/traits.d#L1826

that std.traits.compiles isnt just a __traits(compiles,... call is evidence of my point
5 days ago

On Wednesday, 15 January 2025 at 21:00:35 UTC, realhet wrote:

>

On Wednesday, 15 January 2025 at 20:27:18 UTC, Steven Schveighoffer wrote:

>

On Wednesday, 15 January 2025 at 12:01:21 UTC, realhet wrote:

>

Also seems like invalid syntax. Where does this come from?

It's in std.typecons.d -> git link

It's in the declaration of enum isTuple(T) = ....

> >

github: f(Specs...)(Tuple!Specs tup)

> >

your post: template f(Specs...)f(T.init);

thats quite the important detail, its pattern matching

« First   ‹ Prev
1 2