Re: __traits getMember is context sensetive?

2015-06-14 Thread John Colvin via Digitalmars-d-learn
On Sunday, 14 June 2015 at 10:16:24 UTC, JDemler wrote: On Sunday, 14 June 2015 at 10:04:35 UTC, John Colvin wrote: [...] If that is the case then i really do not get why my first example compiles and my second does not. The compiler sees the pragma(msg, test(e)) and runs test(e). If test u

Re: __traits getMember is context sensetive?

2015-06-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Jun 2015 10:29:08 +, anonymous wrote: > One important thing I didn't see stated clearly by anyone in here: > > CTFE may run at compile time but it follows the same rules as run time > evaluation (plus some restrictions). > > This means, you can't use dynamic values (e.g. function

Re: __traits getMember is context sensetive?

2015-06-14 Thread anonymous via Digitalmars-d-learn
On Sunday, 14 June 2015 at 10:41:24 UTC, JDemler wrote: So if i want to use parameters in a static context at compile time i have to pass them as template parameters? Yes, template parameters are fine.

Re: __traits getMember is context sensetive?

2015-06-14 Thread JDemler via Digitalmars-d-learn
On Sunday, 14 June 2015 at 10:29:09 UTC, anonymous wrote: On Sunday, 14 June 2015 at 10:10:51 UTC, ketmar wrote: i.e. when it need a value in compile time. the interpreter is invoked, it evaluates (interprets) the given code (function or template instantiation), and then it returns result (or r

Re: __traits getMember is context sensetive?

2015-06-14 Thread anonymous via Digitalmars-d-learn
On Sunday, 14 June 2015 at 10:10:51 UTC, ketmar wrote: i.e. when it need a value in compile time. the interpreter is invoked, it evaluates (interprets) the given code (function or template instantiation), and then it returns result (or raises an error). One important thing I didn't see stated

Re: __traits getMember is context sensetive?

2015-06-14 Thread JDemler via Digitalmars-d-learn
On Sunday, 14 June 2015 at 10:04:35 UTC, John Colvin wrote: On Sunday, 14 June 2015 at 09:46:56 UTC, JDemler wrote: On Sunday, 14 June 2015 at 05:52:00 UTC, ketmar wrote: oh, seems that i managed to make everything even less understandable... Your code works perfectly and makes at least some

Re: __traits getMember is context sensetive?

2015-06-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Jun 2015 09:46:54 +, JDemler wrote: > On Sunday, 14 June 2015 at 05:52:00 UTC, ketmar wrote: >> oh, seems that i managed to make everything even less understandable... > > Your code works perfectly and makes at least some sense to me. > Thank you. > > If i understand it correctly:

Re: __traits getMember is context sensetive?

2015-06-14 Thread John Colvin via Digitalmars-d-learn
On Sunday, 14 June 2015 at 09:46:56 UTC, JDemler wrote: On Sunday, 14 June 2015 at 05:52:00 UTC, ketmar wrote: oh, seems that i managed to make everything even less understandable... Your code works perfectly and makes at least some sense to me. Thank you. If i understand it correctly: __tr

Re: __traits getMember is context sensetive?

2015-06-14 Thread JDemler via Digitalmars-d-learn
On Sunday, 14 June 2015 at 05:52:00 UTC, ketmar wrote: oh, seems that i managed to make everything even less understandable... Your code works perfectly and makes at least some sense to me. Thank you. If i understand it correctly: __traits-time = templateinstatiation-time = pragma-time befo

Re: __traits getMember is context sensetive?

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Jun 2015 23:55:53 +, JDemler wrote: > After a bit of rethinking: > > I guess the compiler goes through 2 loops: > the first resolves __traits, the second does ctfe. > > That would explain this behavior. "a" is not present to the compiler > while it tries to resolve my __traits cal

Re: __traits getMember is context sensetive?

2015-06-13 Thread ketmar via Digitalmars-d-learn
oh, seems that i managed to make everything even less understandable... signature.asc Description: PGP signature

Re: __traits getMember is context sensetive?

2015-06-13 Thread JDemler via Digitalmars-d-learn
On Saturday, 13 June 2015 at 23:51:32 UTC, JDemler wrote: I have another one :) module test; struct S{ string member1; int member2; } string test(string[] a) { const S s = { member1:"It is also important to go to Mars!"}; const string y = a[0]; return y; } void main() { enum e = [

Re: __traits getMember is context sensetive?

2015-06-13 Thread JDemler via Digitalmars-d-learn
I have another one :) module test; struct S{ string member1; int member2; } string test(string[] a) { const S s = { member1:"It is also important to go to Mars!"}; const string y = a[0]; return y; } void main() { enum e = ["member1","member2"]; pragma(msg, e[0]); pragma(msg, te

Re: __traits getMember is context sensetive?

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Jun 2015 10:36:39 +, John Colvin wrote: > *for some reason it's not public, but it's very short and simple: it's funny how many useful things are there in Phobos, carefully hidden from user. i believe each D book should include an advice like this: "to fully learn what you can do

Re: __traits getMember is context sensetive?

2015-06-13 Thread John Colvin via Digitalmars-d-learn
On Saturday, 13 June 2015 at 10:01:45 UTC, JDemler wrote: Hey, i am trying to wrap my head around __traits. One thing i just do not understand is following: struct S{ string member1; int member2; } void main(string[] args) { foreach(typeStr; __traits(allMembers, S)) { auto tp

Re: __traits getMember is context sensetive?

2015-06-13 Thread JDemler via Digitalmars-d-learn
On Saturday, 13 June 2015 at 10:26:06 UTC, Marc Schütz wrote: On Saturday, 13 June 2015 at 10:01:45 UTC, JDemler wrote: Hey, i am trying to wrap my head around __traits. One thing i just do not understand is following: struct S{ string member1; int member2; } void main(string[] args) {

Re: __traits getMember is context sensetive?

2015-06-13 Thread via Digitalmars-d-learn
On Saturday, 13 June 2015 at 10:01:45 UTC, JDemler wrote: Hey, i am trying to wrap my head around __traits. One thing i just do not understand is following: struct S{ string member1; int member2; } void main(string[] args) { foreach(typeStr; __traits(allMembers, S)) { auto tp

__traits getMember is context sensetive?

2015-06-13 Thread JDemler via Digitalmars-d-learn
Hey, i am trying to wrap my head around __traits. One thing i just do not understand is following: struct S{ string member1; int member2; } void main(string[] args) { foreach(typeStr; __traits(allMembers, S)) { auto tp = __traits(getMember, S, typeStr); static if (__trait