Re: Why is creating of if Expressions not allowed?

2019-03-24 Thread sighoya via Digitalmars-d-learn
On Sunday, 24 March 2019 at 18:59:45 UTC, Adam D. Ruppe wrote: Think of mixin() not as pasting code per se, but pasting an AST node inside the compiler's data structures. It must be a complete node of that tree that can be substituted in. And because AST Nodes aren't expressions means you

Re: Another Tuesday (Friday?), Another GtkDcoding Blog Post

2019-03-24 Thread Ron Tarrant via Digitalmars-d-learn
Sunday Blog eXtra: Installing and Using a Linux Build Environment URL: http://gtkdcoding.com/2019/03/24/x0002-gtkd-in-a-linux-environment.html

Re: Why is creating of if Expressions not allowed?

2019-03-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 24 March 2019 at 18:18:39 UTC, sighoya wrote: Hmm..., sounds like bad news. Is there any mixin technology for statements? mixin() works for statements too. It is the *context* though. If mixin() appears where the compiler expects an expression, it must give an expression. Ditto

Re: Why is creating of if Expressions not allowed?

2019-03-24 Thread sighoya via Digitalmars-d-learn
On Sunday, 24 March 2019 at 18:43:51 UTC, Paul Backus wrote: You can't return the result of a string mixin from a function. Instead, return a string from your `GenIf` function, and mix it in at the call site: string GenIf() { return "if (true) { return true; } else { return false; }"; }

Re: Why is creating of if Expressions not allowed?

2019-03-24 Thread Alex via Digitalmars-d-learn
On Sunday, 24 March 2019 at 18:18:39 UTC, sighoya wrote: Hmm..., sounds like bad news. Is there any mixin technology for statements? There was a recent thread on this. https://forum.dlang.org/post/mailman.6499.1547823247.29801.digitalmar...@puremagic.com However, do you have a clear use

Re: Why is creating of if Expressions not allowed?

2019-03-24 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 24 March 2019 at 16:18:49 UTC, sighoya wrote: Why auto GenIf()() { return mixin("if(true) { return true;} else {return false;}"); } public bool testFunction2() { GenIf!(); } gives me: onlineapp.d-mixin-3(3): Error: expression expected, not if onlineapp.d(8): Error:

Re: Why is creating of if Expressions not allowed?

2019-03-24 Thread sighoya via Digitalmars-d-learn
On Sunday, 24 March 2019 at 16:57:25 UTC, Rémy Mouëza wrote: On Sunday, 24 March 2019 at 16:18:49 UTC, sighoya wrote: Why auto GenIf()() { return mixin("if(true) { return true;} else {return false;}"); } public bool testFunction2() { GenIf!(); } gives me: onlineapp.d-mixin-3(3):

Re: Why is creating of if Expressions not allowed?

2019-03-24 Thread Rémy Mouëza via Digitalmars-d-learn
On Sunday, 24 March 2019 at 16:18:49 UTC, sighoya wrote: Why auto GenIf()() { return mixin("if(true) { return true;} else {return false;}"); } public bool testFunction2() { GenIf!(); } gives me: onlineapp.d-mixin-3(3): Error: expression expected, not if onlineapp.d(8): Error:

Why is creating of if Expressions not allowed?

2019-03-24 Thread sighoya via Digitalmars-d-learn
Why auto GenIf()() { return mixin("if(true) { return true;} else {return false;}"); } public bool testFunction2() { GenIf!(); } gives me: onlineapp.d-mixin-3(3): Error: expression expected, not if onlineapp.d(8): Error: template instance `onlineapp.GenIf!()` error instantiating

Re: "if" statement

2019-03-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.03.19 13:45, Francesco Mecca wrote: ``` alias Alg = Algebraic!(int, string); void main() { int n = 2;     Alg value;     value = n == 2 ? 2 : "string"; } ``` The original code used SumType but the effect is the same. I suppose that I could write the following: ```     if(n ==

"if" statement

2019-03-24 Thread Francesco Mecca via Digitalmars-d-learn
https://run.dlang.io/is/zRcj59 ``` alias Alg = Algebraic!(int, string); void main() { int n = 2; Alg value; value = n == 2 ? 2 : "string"; } ``` The original code used SumType but the effect is the same. I suppose that I could write the following: ``` if(n == 2) value =

Re: Another Tuesday (Friday?), Another GtkDcoding Blog Post

2019-03-24 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 23 March 2019 at 07:18:02 UTC, number wrote: The first one :), now there's still the other one "Here’s a second code file for you." Done. Thanks, eh.