Re: length's type.

2024-01-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 17, 2024 11:33:48 PM MST zjh via Digitalmars-d-learn wrote: > On Thursday, 18 January 2024 at 04:30:33 UTC, Jonathan M Davis > wrote: > but for a lot of code, using auto and size_t makes it > > > so that you don't need to use int, and it would be a big > > problem in general

Re: length's type.

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 04:30:33 UTC, Jonathan M Davis wrote: but for a lot of code, using auto and size_t makes it so that you don't need to use int, and it would be a big problem in general if the language made length int. It's hard to imagine that an `'int'` needs to be replaced

Re: vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 04:24:18 UTC, zjh wrote: ```d class V : ASTVisitor { Vector!string f=[]; alias visit = ASTVisitor.visit; override void visit(const FunctionDeclaration decl) { writeln(' '.repeat(indentLevel * 4), decl.name.text);

Re: length's type.

2024-01-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 17, 2024 7:55:37 PM MST zjh via Digitalmars-d-learn wrote: > Can you change the type of 'length' from 'ulong' to 'int', so I > haven't to convert it every time! If you mean for arrays, length and array indices are specifically size_t so that their size will match the

Re: vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 04:20:12 UTC, zjh wrote: foreach(e;d){ ```d foreach(e;d){//.0 string b=e; string m=readText(b);ff(m,b); } ``` or here `.0`? why crash?

Re: vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:53:09 UTC, Steven Schveighoffer wrote: Are you sure this is what you are wanting to do? -Steve ```d void gg(string a){ Vector!string d=[];toV(a,d);//File to Vector print(d);//3,OK foreach(e;d){ string b=e;//.1 string

Re: vector crash

2024-01-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:07:13 UTC, zjh wrote: ```d import dparse.ast; import dparse.lexer; import dparse.parser : parseModule; import dparse.rollback_allocator : RollbackAllocator; import core.stdcpp.vector; import core.stdcpp.string; ... ``` I have no experience with using cpp from

Re: vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:11:57 UTC, zjh wrote: ```d string b=d[i];//the 3th:vector.d //`+Object`,crashes! ``` ```d //d[i]==>e string b=e; ``` in the foreach.

Re: vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:07:13 UTC, zjh wrote: Why can `b` still affect `e` here? Isn't `b` copied? here foreach crashes. Starting from the `third one`, it crashes. It's clearly `vector.d`, but the result is`+Object`. ```d string b=d[i];//the 3th:vector.d //`+Object`,crashes! ```

vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
```d import dparse.ast; import dparse.lexer; import dparse.parser : parseModule; import dparse.rollback_allocator : RollbackAllocator; import core.stdcpp.vector; import core.stdcpp.string; Vector!string d=[];toV(a,d); print(d);//3 foreach(e;d){ string b=d[i]; string

Re: hunt-examples/website-basic

2024-01-17 Thread Heromyth via Digitalmars-d-learn
On Saturday, 29 April 2023 at 18:05:20 UTC, Vino B wrote: Hi All, Request your help, while trying to compile the hunt-examples/website-basic, I am facing with the below error(https://github.com/huntlabs/hunt-examples/tree/master/website-basic). Error ```

Re: Understanding the Use of Nested Import and Selective Import in D

2024-01-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 17, 2024 7:03:18 AM MST Renato via Digitalmars-d-learn wrote: > My main reasoning is that D tools, surprisingly, cannot do > "Optimize Imports" (turns out that with all the metaprogramming > going on , it's impossible to tell for sure which imports are > being used - or so I

Re: compute from a string the text of a string literal

2024-01-17 Thread Carl Sturtivant via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 18:53:48 UTC, Paul Backus wrote: There's a function that does this in Phobos, but it's `private`. Currently, the only way to access it is by calling `to!string` or `format` on a range that contains the string you want to convert as an element: ```d void

Re: compute from a string the text of a string literal

2024-01-17 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 18:44:14 UTC, Carl Sturtivant wrote: Hello, I'd like a function like this, ``` string image(string s) ``` that maps any string s into the doubly quoted backslash escaped text that would be a string literal for s were it pasted into a program. Perhaps with a

compute from a string the text of a string literal

2024-01-17 Thread Carl Sturtivant via Digitalmars-d-learn
Hello, I'd like a function like this, ``` string image(string s) ``` that maps any string s into the doubly quoted backslash escaped text that would be a string literal for s were it pasted into a program. Perhaps with a second parameter with detailed options. Is there something out there I

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread Renato via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 16:30:08 UTC, H. S. Teoh wrote: On Wed, Jan 17, 2024 at 07:19:39AM +, Renato via Digitalmars-d-learn wrote: [...] But pls run the benchmarks yourself as I am not going to keep running it for you, and would be nice if you posted your solution on a Gist for

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 17, 2024 at 07:57:02AM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > I'll push the code to github. [...] Here: https://github.com/quickfur/prechelt/blob/master/encode_phone.d T -- Why do conspiracy theories always come from the same people??

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 17, 2024 at 07:19:39AM +, Renato via Digitalmars-d-learn wrote: [...] > But pls run the benchmarks yourself as I am not going to keep running > it for you, and would be nice if you posted your solution on a Gist > for example, pasting lots of code in the forum makes it difficult to

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 17, 2024 at 07:19:39AM +, Renato via Digitalmars-d-learn wrote: > On Tuesday, 16 January 2024 at 22:13:55 UTC, H. S. Teoh wrote: > > used for the recursive calls. Getting rid of the .format ought to > > speed it up a bit. Will try that now... > > > > That will make no difference

Re: Understanding the Use of Nested Import and Selective Import in D

2024-01-17 Thread Renato via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 13:38:10 UTC, Orfeo wrote: On Tuesday, 16 January 2024 at 19:05:43 UTC, Jonathan M Davis wrote: When local imports were introduced, they were pushed as best practice (in part, because Andrei is a big fan of them), and I think that for the most part, they

Re: Understanding the Use of Nested Import and Selective Import in D

2024-01-17 Thread Orfeo via Digitalmars-d-learn
On Tuesday, 16 January 2024 at 19:05:43 UTC, Jonathan M Davis wrote: When local imports were introduced, they were pushed as best practice (in part, because Andrei is a big fan of them), and I think that for the most part, they still are, but there's definitely going to be some disagreement

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread Renato via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 11:56:19 UTC, evilrat wrote: On Wednesday, 17 January 2024 at 11:20:14 UTC, Renato wrote: That means the input file is still not ASCII (or UTF-8) as it should. Java is reading files with the ASCII encoding so it should've worked fine. It seems that it is

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread evilrat via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 11:20:14 UTC, Renato wrote: That means the input file is still not ASCII (or UTF-8) as it should. Java is reading files with the ASCII encoding so it should've worked fine. It seems that it is only works with ASCII encoding though.

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread Renato via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 10:50:26 UTC, evilrat wrote: On Wednesday, 17 January 2024 at 10:43:22 UTC, Renato wrote: On Wednesday, 17 January 2024 at 10:24:31 UTC, Renato wrote: It's not Java writing the file, it's the bash script

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread evilrat via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 10:43:22 UTC, Renato wrote: On Wednesday, 17 January 2024 at 10:24:31 UTC, Renato wrote: It's not Java writing the file, it's the bash script [`benchmark.sh`](https://github.com/renatoathaydes/prechelt-phone-number-encoding/blob/master/benchmark.sh#L31): ```

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread Renato via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 10:24:31 UTC, Renato wrote: It's not Java writing the file, it's the bash script [`benchmark.sh`](https://github.com/renatoathaydes/prechelt-phone-number-encoding/blob/master/benchmark.sh#L31): ``` java -cp "build/util" util.GeneratePhoneNumbers 1000 >

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread Renato via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 09:15:02 UTC, evilrat wrote: On Wednesday, 17 January 2024 at 07:11:02 UTC, Renato wrote: If you want to check your performance, you know you can run the `./benchmark.sh` yourself? Out of curiosity I've tried to manually run this on Windows and it seems

Re: Would you recommend TDPL today?

2024-01-17 Thread Paolo Invernizzi via Digitalmars-d-learn
On Tuesday, 16 January 2024 at 02:25:32 UTC, matheus wrote: Hi, I'm mostly a lurker in these Forums but sometimes I post here and there, my first language was C and I still use today together with my own library (A Helper) which is like a poor version of STB (https://github.com/nothings/stb).

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread evilrat via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 07:06:25 UTC, Renato wrote: On Tuesday, 16 January 2024 at 22:15:04 UTC, Siarhei Siamashka wrote: On Tuesday, 16 January 2024 at 21:15:19 UTC, Renato wrote: It's a GC allocations fest. Things like this make it slow: ```diff { -string digit =

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread evilrat via Digitalmars-d-learn
On Wednesday, 17 January 2024 at 07:11:02 UTC, Renato wrote: If you want to check your performance, you know you can run the `./benchmark.sh` yourself? Out of curiosity I've tried to manually run this on Windows and it seems that Java generator for these numbers files is "broken", the

Re: Nested delegates and closure allocations

2024-01-17 Thread Anonymouse via Digitalmars-d-learn
On Tuesday, 16 January 2024 at 17:21:12 UTC, FeepingCreature wrote: Correct. [...] Thanks, I think I understand.