October 14, 2019
On Monday, 14 October 2019 at 13:00:14 UTC, Dukc wrote:
> But I still think an `if_not`, `ifnot` or some similar keyword would have it's place. Does anybody agree? Read: might it be worth a DIP?

I think a new keyword for this has very little chance.
One related idea is making `if !(expression) statement` allowed in the grammar (! outside parentheses) which makes it easier to read fully negated if-statements. It hasn't been that well received though:

https://github.com/dlang/dmd/pull/8440
https://forum.dlang.org/post/pgkv3t$15te$1@digitalmars.com

October 14, 2019
On Monday, 14 October 2019 at 13:00:14 UTC, Dukc wrote:
> On Saturday, 12 October 2019 at 16:48:56 UTC, Jesse Phillips wrote:
>>
>> Sorry forgot the foreach break part.
>>
>> import std.stdio;
>> void main()
>> {
>> import std.algorithm;
>> import std.range;
>>
>> foreach(i; iota(10)
>>     .filter!(x => x%2)
>>     .until!(x => x>5)
>>     .map!"a * a"
>>     .filter!(x => x%4)) {
>>     i.writeln;
>>     break;
>>    }
>> }
>>
>> Note this is all done lazily so there is no walking of the iota which happens.
>
> This is not exactly what I wanted, but probably the best alternative overall. At least it's better than in C#, as you don't sacrifice as much performance for using functional pipelines.

Pretty sure you don't need the foreach loop in this example; you can just use `take`:

iota(10)
    .filter!(x => x%2)
    // ...
    .take(1)
    .each!writeln;
October 14, 2019
On Monday, 14 October 2019 at 13:00:14 UTC, Dukc wrote:
> On Saturday, 12 October 2019 at 16:48:56 UTC, Jesse Phillips wrote:
>>
>> Sorry forgot the foreach break part.
>>
>> import std.stdio;
>> void main()
>> {
>> import std.algorithm;
>> import std.range;
>>
>> foreach(i; iota(10)
>>     .filter!(x => x%2)
>>     .until!(x => x>5)
>>     .map!"a * a"
>>     .filter!(x => x%4)) {
>>     i.writeln;
>>     break;
>>    }
>> }
>>
>> Note this is all done lazily so there is no walking of the iota which happens.
>
> This is not exactly what I wanted, but probably the best alternative overall. At least it's better than in C#, as you don't sacrifice as much performance for using functional pipelines.

How is not what you want? I realize it doesn't use the same foreach break structure, but then there is no alternative.

>
> But I still think an `if_not`, `ifnot` or some similar keyword would have it's place. Does anybody agree? Read: might it be worth a DIP?

I don't think it is worth it and I do think the range based approach is direction people should head.


October 16, 2019
On Monday, 14 October 2019 at 13:26:56 UTC, Dennis wrote:
>
> I think a new keyword for this has very little chance.
> One related idea is making `if !(expression) statement` allowed in the grammar (! outside parentheses) which makes it easier to read fully negated if-statements.

Would also do the trick imo, and also avoid a new keyword. Good idea.

> It hasn't been that well received though:
>
> https://github.com/dlang/dmd/pull/8440
> https://forum.dlang.org/post/pgkv3t$15te$1@digitalmars.com

Thanks for those links - I didn't know that `if !(condition)` is allowed in C#. That's useful.
October 16, 2019
On Monday, 14 October 2019 at 15:26:03 UTC, Jesse Phillips wrote:
> How is not what you want? I realize it doesn't use the same foreach break structure, but then there is no alternative.

I think you nailed it - there is apparently no (better) alternative currently. So it's down to discussing DIP or no, and if yes, what should it propose.

>
>>
>> But I still think an `if_not`, `ifnot` or some similar keyword would have it's place. Does anybody agree? Read: might it be worth a DIP?
>
> I don't think it is worth it and I do think the range based approach is direction people should head.

After reading what Dennis wrote, I think I agree that relaxing parenthesis requirements for `if` statements (and perhaps `while`/`switch`/`with` while on it) is a better way to go.

But while I agree that pursuing range pipelines is a good general diretion, sometimes it is just more practical to do stuff in the imperative way - the langauge should not discourage that.


1 2
Next ›   Last »