Re: "if not" condition check (for data validation)

2020-06-18 Thread Denis via Digitalmars-d-learn
Let me clarify the requirements and rephrase the question -- REQUIREMENTS `assert`, `enforce` and the `unless` function I wrote (above) all allow the condition to be expressed in an affirmative sense, and they also achieve the goal of readability. These are the initial requirements.

Re: "if not" condition check (for data validation)

2020-06-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 18 June 2020 at 12:13:21 UTC, Denis wrote: THE ESSENTIAL QUESTION Is there a way to write an `unless` operator that would allow the condition to be expressed in an affirmative sense? It would be used like `if`, i.e. something like: unless ( ) { ; // Or even:

Parallel array append using std.parallelism?

2020-06-18 Thread H. S. Teoh via Digitalmars-d-learn
I have an array of input data that I'm looping over, and, based on some condition, generate new items that are appended onto a target array (which may already contain data). Since the creation of new items is quite expensive, I'm thinking to parallelize it with parallel foreach. To avoid data

Re: "if not" condition check (for data validation)

2020-06-18 Thread Dukc via Digitalmars-d-learn
On Thursday, 18 June 2020 at 13:57:39 UTC, Dukc wrote: if (not!(abra && cadabra)) ... if (not(abra && cadabra)) ...

Re: "if not" condition check (for data validation)

2020-06-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 18 June 2020 at 13:57:39 UTC, Dukc wrote: No reason to use templates here Pff. Me no think straight. -.-

Re: Why is there no std.stream anymore?

2020-06-18 Thread aberba via Digitalmars-d-learn
On Tuesday, 12 December 2017 at 20:51:30 UTC, Steven Schveighoffer wrote: On 12/11/17 6:33 PM, Seb wrote: [...] Since iopipe was mentioned several times, I will say a couple things: [...] I should really try iopipe this time round. I think I avoided toying with it because the making

Re: "if not" condition check (for data validation)

2020-06-18 Thread Dukc via Digitalmars-d-learn
On Thursday, 18 June 2020 at 12:50:35 UTC, Stanislav Blinov wrote: auto not(alias cond)() { return !cond(); } if (not!(() => abra && cadabra)) ... but that is indeed even less readable. No reason to use templates here ``` pragma(inline, true) auto not(bool cond) { return !cond(); } if

Re: Should a parser type be a struct or class?

2020-06-18 Thread welkam via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 14:32:09 UTC, Adam D. Ruppe wrote: On Wednesday, 17 June 2020 at 14:24:01 UTC, Stefan Koch wrote: Parser in dmd does even inherit from Lexer. why would a parser ever inherit from a lexer? So you can write nextToken() instead of lexer.nextToken()

Re: Why is there no std.stream anymore?

2020-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/20 10:53 AM, aberba wrote: On Tuesday, 12 December 2017 at 20:51:30 UTC, Steven Schveighoffer wrote: On 12/11/17 6:33 PM, Seb wrote: [...] Since iopipe was mentioned several times, I will say a couple things: [...] I should really try iopipe this time round. I think I avoided

Re: Why is there no std.stream anymore?

2020-06-18 Thread aberba via Digitalmars-d-learn
On Thursday, 18 June 2020 at 15:03:38 UTC, Steven Schveighoffer wrote: On 6/18/20 10:53 AM, aberba wrote: On Tuesday, 12 December 2017 at 20:51:30 UTC, Steven Schveighoffer wrote: On 12/11/17 6:33 PM, Seb wrote: [...] Since iopipe was mentioned several times, I will say a couple things:

Re: "if not" condition check (for data validation)

2020-06-18 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 18 June 2020 at 13:58:33 UTC, Dukc wrote: On Thursday, 18 June 2020 at 13:57:39 UTC, Dukc wrote: if (not!(abra && cadabra)) ... if (not(abra && cadabra)) ... Which is a quite a complicated way to write if (!(abra && cadabra)) ...

Re: Should a parser type be a struct or class?

2020-06-18 Thread welkam via Digitalmars-d-learn
Oh an also https://github.com/dlang/dmd/pull/9899

Re: "if not" condition check (for data validation)

2020-06-18 Thread Denis via Digitalmars-d-learn
On Thursday, 18 June 2020 at 12:50:35 UTC, Stanislav Blinov wrote: No, there isn't a way to write an operator. OK, first choice eliminated. On Thursday, 18 June 2020 at 13:57:39 UTC, Dukc wrote: No reason to use templates here pragma(inline, true) auto not(bool cond) { return !cond(); } I

Re: "if not" condition check (for data validation)

2020-06-18 Thread Ali Çehreli via Digitalmars-d-learn
On 6/18/20 5:13 AM, Denis wrote: > Templates offer a clean syntax Here is an earlier experiment of nested templates, which may be useful in this case. This is unrelated to your problem but the syntax can be pretty readable with templates: // If there are template arguments, then the result

Re: Should a parser type be a struct or class?

2020-06-18 Thread Meta via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 11:50:27 UTC, Per Nordlöw wrote: Should a range-compliant aggregate type realizing a parser be encoded as a struct or class? In dmd `Lexer` and `Parser` are both classes. In general how should I reason about whether an aggregate type should be encoded as a

Re: "if not" condition check (for data validation)

2020-06-18 Thread Denis via Digitalmars-d-learn
On Thursday, 18 June 2020 at 17:57:49 UTC, Ali Çehreli wrote: Here is an earlier experiment of nested templates, which may be useful in this case. : I think you should be able to pass callables as 'alias' template arguments Sounds good. This gives me an opportunity to learn how nested

Re: Why is there no std.stream anymore?

2020-06-18 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 18 June 2020 at 14:53:58 UTC, aberba wrote: On Tuesday, 12 December 2017 at 20:51:30 UTC, Steven Schveighoffer wrote: On 12/11/17 6:33 PM, Seb wrote: [...] Since iopipe was mentioned several times, I will say a couple things: [...] I should really try iopipe this time round.