splitter and matcher combined regex

2019-06-16 Thread Amex via Digitalmars-d-learn
Having to split and match seems slow(50%). Surely the regex splitter and matcher can be combined? Sometimes we just need to extract out and remove information simultaneously. I propose a new function called extractor that returns the matchAll and splitter's results but is optimized.

CT/RT annoyance

2019-06-16 Thread Bart via Digitalmars-d-learn
Consider void foo(string A = "")(string B = "") { static if (A != "") do(A); else do(B); } foo!("x"); foo("x"); This is necessary because D's templating and meta programming system is frail. While CTFE should take care of such things, it does not, consider

Re: Range violation error when reading from a file

2019-06-16 Thread Norm via Digitalmars-d-learn
On Monday, 17 June 2019 at 00:22:23 UTC, Samir wrote: On Sunday, 16 June 2019 at 23:55:41 UTC, lithium iodate wrote: There is *very* likely to be a terminating new-line at the end of the file (many editors add one without asking!). If that the case, the last line seen by the loop will be empty

Re: Range violation error when reading from a file

2019-06-16 Thread Samir via Digitalmars-d-learn
On Sunday, 16 June 2019 at 23:55:41 UTC, lithium iodate wrote: There is *very* likely to be a terminating new-line at the end of the file (many editors add one without asking!). If that the case, the last line seen by the loop will be empty and you must not attempt to access any elements. On

Re: Range violation error when reading from a file

2019-06-16 Thread aliak via Digitalmars-d-learn
On Sunday, 16 June 2019 at 23:44:49 UTC, Samir wrote: On Sunday, 16 June 2019 at 23:03:04 UTC, aliak wrote: stripping the last line could result in an empty line if it just has strippable characters? The last line of the file is just text but without a newline (\n) character or any other

Re: Range violation error when reading from a file

2019-06-16 Thread lithium iodate via Digitalmars-d-learn
On Sunday, 16 June 2019 at 23:44:49 UTC, Samir wrote: On Sunday, 16 June 2019 at 23:03:04 UTC, aliak wrote: stripping the last line could result in an empty line if it just has strippable characters? The last line of the file is just text but without a newline (\n) character or any other

Re: Range violation error when reading from a file

2019-06-16 Thread Samir via Digitalmars-d-learn
On Sunday, 16 June 2019 at 23:03:04 UTC, aliak wrote: stripping the last line could result in an empty line if it just has strippable characters? The last line of the file is just text but without a newline (\n) character or any other whitespace character at the end. I get the same error

Re: Range violation error when reading from a file

2019-06-16 Thread Samir via Digitalmars-d-learn
On Sunday, 16 June 2019 at 23:03:04 UTC, aliak wrote: stripping the last line could result in an empty line if it just has strippable characters? The last line is just the text of the last line. There is no newline character at the end. I also get the same error if I remove the strip

Re: Range violation error when reading from a file

2019-06-16 Thread aliak via Digitalmars-d-learn
On Sunday, 16 June 2019 at 22:47:14 UTC, Samir wrote: I am trying to read from a text file using the following code: import std.stdio; import std.string; void main() { File file = File("test.txt"); string line; while (!file.eof()) { line = strip(file.readln()); if

Range violation error when reading from a file

2019-06-16 Thread Samir via Digitalmars-d-learn
I am trying to read from a text file using the following code: import std.stdio; import std.string; void main() { File file = File("test.txt"); string line; while (!file.eof()) { line = strip(file.readln()); if (line[0] == '>') { // line 10

Re: Suggest aesthetic way to Naming a module or a package with illegal lexical D lang keywords

2019-06-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 16, 2019 5:53:30 AM MDT BoQsc via Digitalmars-d-learn wrote: > On Sunday, 16 June 2019 at 11:38:27 UTC, rikki cattermole wrote: > > The style guide has an opinion about this (you don't have to > > follow it). > > > > https://dlang.org/dstyle.html#naming_keywords > > So if I follow

How does this template work?

2019-06-16 Thread Robert M. Münch via Digitalmars-d-learn
How does the observerObject Template and function work? I'm struggling because both use the same name and how is the template parameter R deduced/where is it coming from? Looks like it's somehow implicitly deduced. class ObserverObject(R, E...){...} template observerObject(E) {

Re: How does this template work?

2019-06-16 Thread rikki cattermole via Digitalmars-d-learn
On 17/06/2019 3:11 AM, Robert M. Münch wrote: How does the observerObject Template and function work? I'm struggling because both use the same name and how is the template parameter R deduced/where is it coming from? Looks like it's somehow implicitly deduced. class ObserverObject(R,

Re: Strange closure behaviour

2019-06-16 Thread Rémy Mouëza via Digitalmars-d-learn
On Sunday, 16 June 2019 at 01:36:38 UTC, Timon Gehr wrote: It's a bug. It's memory corruption. Different objects with overlapping lifetimes use the same memory location. Okay. Seen that way, it is clear to me why it's a bug. ... No, it's not the same. Python has no sensible notion of

Re: Suggest aesthetic way to Naming a module or a package with illegal lexical D lang keywords

2019-06-16 Thread BoQsc via Digitalmars-d-learn
On Sunday, 16 June 2019 at 11:38:27 UTC, rikki cattermole wrote: The style guide has an opinion about this (you don't have to follow it). https://dlang.org/dstyle.html#naming_keywords So if I follow dstyle guidelines on keywords, this would be a correct non-conflicting result: module

Re: Suggest aesthetic way to Naming a module or a package with illegal lexical D lang keywords

2019-06-16 Thread rikki cattermole via Digitalmars-d-learn
The style guide has an opinion about this (you don't have to follow it). https://dlang.org/dstyle.html#naming_keywords

Suggest aesthetic way to Naming a module or a package with illegal lexical D lang keywords

2019-06-16 Thread BoQsc via Digitalmars-d-learn
Do not ask why I want to do that, you can however suggest alternative variations. As you all might know, 2. The Identifiers preceding the rightmost are the Packages that the module is in. The packages correspond to directory names in the source file path. Package and module names cannot be