Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 11:56:40 UTC, rikki cattermole wrote: void bar (T ...) (T args) if (T.length == 0) { return; [...] } void bar (T ...) (T args) if (T.length > 0) { writeln (args [0]); return bar (args [1 .. $]); } This is a version without a

Re: guard clause style static if

2018-07-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/10/18 7:38 AM, kdevel wrote: On Tuesday, 10 July 2018 at 00:11:27 UTC, Steven Schveighoffer wrote: On 7/7/18 7:28 AM, kdevel wrote: It appears not to be possible to use static if in "guard clause style" as in     void bar (T ...) (T args)     {    static if (args.length == 0)    

Re: guard clause style static if

2018-07-10 Thread Timoses via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 12:10:27 UTC, Jonathan M Davis wrote: On Tuesday, 10 July 2018 05:38:33 MDT kdevel via Digitalmars-d-learn wrote: I would like to suggest an extension of the language by introducing static return Expression_opt; which shall have the effect of a return plus

Re: guard clause style static if

2018-07-10 Thread Timoses via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 12:05:11 UTC, kdevel wrote: On Saturday, 7 July 2018 at 13:12:59 UTC, Alex wrote: The site you cited for the guard clause above (c2.com) works at runtime. ? static if works at compile team and only inserts code into the final code for run-time depending on the

Re: guard clause style static if

2018-07-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, 10 July 2018 05:38:33 MDT kdevel via Digitalmars-d-learn wrote: > I would like to suggest an extension of the language by > introducing > > static return Expression_opt; > > which shall have the effect of a return plus that the remaining > lines in the current block are treated as

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 13:12:59 UTC, Alex wrote: The site you cited for the guard clause above (c2.com) works at runtime. ? The intention is to shorten the paths inside a function, I think. Therefore, a static "guard clause" is a contradiction, if I understand it correctly. The term

Re: guard clause style static if

2018-07-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, 10 July 2018 05:52:59 MDT kdevel via Digitalmars-d-learn wrote: > On Saturday, 7 July 2018 at 13:03:32 UTC, rikki cattermole wrote: > > void func() { > > > > return; > > > > func2(); > > > > } > > > > Which is clearly an error. Hence why you need to add else block. > > There is

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 13:03:32 UTC, rikki cattermole wrote: void func() { return; func2(); } Which is clearly an error. Hence why you need to add else block. There is no error in this generated code because func2 is unreachable. That there is a state/stage during

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 00:11:27 UTC, Steven Schveighoffer wrote: On 7/7/18 7:28 AM, kdevel wrote: It appears not to be possible to use static if in "guard clause style" as in    void bar (T ...) (T args)    {   static if (args.length == 0) return;   writeln (args

Re: guard clause style static if

2018-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/7/18 7:28 AM, kdevel wrote: It appears not to be possible to use static if in "guard clause style" as in    void bar (T ...) (T args)    {   static if (args.length == 0) return;   writeln (args [0]);   return bar (args [1 .. $]);    } Is this intended? Yes.

Re: guard clause style static if

2018-07-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 July 2018 at 12:54:03 UTC, kdevel wrote: On Saturday, 7 July 2018 at 12:46:08 UTC, rikki cattermole wrote: On 08/07/2018 12:40 AM, kdevel wrote: Interesting alternative That was not an alternative. That is what your code was doing. What my original code was supposed to do.

Re: guard clause style static if

2018-07-07 Thread rikki cattermole via Digitalmars-d-learn
On 08/07/2018 12:54 AM, kdevel wrote: On Saturday, 7 July 2018 at 12:46:08 UTC, rikki cattermole wrote: On 08/07/2018 12:40 AM, kdevel wrote: Interesting alternative That was not an alternative. That is what your code was doing. What my original code was supposed to do. But it did not

Re: guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 12:46:08 UTC, rikki cattermole wrote: On 08/07/2018 12:40 AM, kdevel wrote: Interesting alternative That was not an alternative. That is what your code was doing. What my original code was supposed to do. But it did not compile. Error: array index [0] is

Re: guard clause style static if

2018-07-07 Thread rikki cattermole via Digitalmars-d-learn
On 08/07/2018 12:40 AM, kdevel wrote: Interesting alternative That was not an alternative. That is what your code was doing.

Re: guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 11:56:40 UTC, rikki cattermole wrote: On 07/07/2018 11:44 PM, kdevel wrote: On Saturday, 7 July 2018 at 11:29:35 UTC, rikki cattermole wrote:    static if (args.length == 0)   return; else {    writeln (args [0]);    return bar (args [1 ..

Re: guard clause style static if

2018-07-07 Thread rikki cattermole via Digitalmars-d-learn
On 07/07/2018 11:44 PM, kdevel wrote: On Saturday, 7 July 2018 at 11:29:35 UTC, rikki cattermole wrote:    static if (args.length == 0)   return; else {    writeln (args [0]);    return bar (args [1 .. $]); } That's not guard clause style [1][2]. [1]

Re: guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 11:29:35 UTC, rikki cattermole wrote:   static if (args.length == 0) return; else {   writeln (args [0]);   return bar (args [1 .. $]); } That's not guard clause style [1][2]. [1]

Re: guard clause style static if

2018-07-07 Thread rikki cattermole via Digitalmars-d-learn
On 07/07/2018 11:28 PM, kdevel wrote: It appears not to be possible to use static if in "guard clause style" as in    void bar (T ...) (T args)    {   static if (args.length == 0) return; else {   writeln (args [0]);   return bar (args [1 .. $]); }    }

guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
It appears not to be possible to use static if in "guard clause style" as in void bar (T ...) (T args) { static if (args.length == 0) return; writeln (args [0]); return bar (args [1 .. $]); } Is this intended?