Re: vector crash

2024-01-20 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:07:13 UTC, zjh wrote: ```d void toV(string a,ref vector!string b){ auto f=File(a,"r"); while(!f.eof()){ string l=strip(f.readln());push(b,l); } Qwk(b); }// ``` There is an issue with the `vector` here, I don't know why the subsequent f

Re: Partial function application (Currying)

2024-01-20 Thread atzensepp via Digitalmars-d-learn
On Saturday, 20 January 2024 at 20:58:49 UTC, Richard (Rikki) Andrew Cattermole wrote: On 21/01/2024 9:55 AM, atzensepp wrote: import std.stdio; // Overloads are resolved when the partially applied function is called // with the remaining arguments. struct S { static char fun(int i, string s) {

Re: macOS Sonoma Linker Issue

2024-01-20 Thread ryuukk_ via Digitalmars-d-learn
On Saturday, 20 January 2024 at 20:35:16 UTC, Renato wrote: On Friday, 22 December 2023 at 17:50:47 UTC, Johan wrote: Some general advice: 1 - use `dub` from LDC's package (this may solve some arm64 vs x86 issues when on Apple Silicon CPU) 2 - when you use a new or different compiler, you have

Re: Partial function application (Currying)

2024-01-20 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 21/01/2024 9:55 AM, atzensepp wrote: import std.stdio; // Overloads are resolved when the partially applied function is called // with the remaining arguments. struct S { static char fun(int i, string s) { return s[i]; } static int fun(int a, int b) { return a * b; } } void main() { alias fu

Re: Partial function application (Currying)

2024-01-20 Thread atzensepp via Digitalmars-d-learn
On Saturday, 20 January 2024 at 17:47:29 UTC, Richard (Rikki) Andrew Cattermole wrote: Not really any other way to do it, create context (i.e. struct, or stack) and have a delegate point to both it and a patch function. It'll be how partial is implemented. https://dlang.org/phobos/std_functio

Re: Partial function application (Currying)

2024-01-20 Thread atzensepp via Digitalmars-d-learn
On Saturday, 20 January 2024 at 17:45:36 UTC, Christian Köstlin wrote: Would https://dlang.org/library/std/functional/curry.html help you? kind regards, Christian Hello Christian, thank for the link. I looks good however in my installation (gdc 8.4.0) it says: ```d curry.d:1:8: error: modul

Re: macOS Sonoma Linker Issue

2024-01-20 Thread Renato via Digitalmars-d-learn
On Friday, 22 December 2023 at 17:50:47 UTC, Johan wrote: Some general advice: 1 - use `dub` from LDC's package (this may solve some arm64 vs x86 issues when on Apple Silicon CPU) 2 - when you use a new or different compiler, you have to rebuild _all_ packages. So clear your dub cache. I thi

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

2024-01-20 Thread Renato via Digitalmars-d-learn
On Saturday, 20 January 2024 at 19:45:19 UTC, Daniel Kozak wrote: On Sat, Jan 20, 2024 at 2:11 PM Renato via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: Wow, fantastic feedback from lots of people, thanks so much! ... > evilrat: > There is another important difference, i

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

2024-01-20 Thread Daniel Kozak via Digitalmars-d-learn
On Sat, Jan 20, 2024 at 2:11 PM Renato via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Wow, fantastic feedback from lots of people, thanks so much! > ... > > > evilrat: > > There is another important difference, i quickly looked up D > > associative array implementation and t

Re: Partial function application (Currying)

2024-01-20 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Not really any other way to do it, create context (i.e. struct, or stack) and have a delegate point to both it and a patch function. It'll be how partial is implemented. https://dlang.org/phobos/std_functional.html#.partial

Re: Partial function application (Currying)

2024-01-20 Thread Christian Köstlin via Digitalmars-d-learn
Would https://dlang.org/library/std/functional/curry.html help you? kind regards, Christian

Partial function application (Currying)

2024-01-20 Thread atzensepp via Digitalmars-d-learn
Hello, D-Language allows for anonymous functions. Is there a way of elegant partial function application such as in other (functional) languages? A function "doemar" accepts a function with one parameter, Another function g defined within mail accepts two parameters and should be applied parti

Re: Delegates and values captured inside loops

2024-01-20 Thread ryuukk_ via Digitalmars-d-learn
On Saturday, 20 January 2024 at 15:59:59 UTC, Anonymouse wrote: I remember reading this was an issue and now I ran into it myself. ```d import std.stdio; void main() { auto names = [ "foo", "bar", "baz" ]; void delegate()[] dgs; foreach (name; names) { dgs ~= () => wri

Re: Delegates and values captured inside loops

2024-01-20 Thread FeepingCreature via Digitalmars-d-learn
On Saturday, 20 January 2024 at 15:59:59 UTC, Anonymouse wrote: I remember reading this was an issue and now I ran into it myself. ```d import std.stdio; void main() { auto names = [ "foo", "bar", "baz" ]; void delegate()[] dgs; foreach (name; names) { dgs ~= () => wri

Re: Delegates and values captured inside loops

2024-01-20 Thread monkyyy via Digitalmars-d-learn
On Saturday, 20 January 2024 at 15:59:59 UTC, Anonymouse wrote: I remember reading this was an issue and now I ran into it myself. ```d import std.stdio; void main() { auto names = [ "foo", "bar", "baz" ]; void delegate()[] dgs; foreach (name; names) { dgs ~= () => wri

Re: trouble with associative Arrays

2024-01-20 Thread Renato via Digitalmars-d-learn
On Saturday, 20 January 2024 at 15:16:00 UTC, atzensepp wrote: The section looks now simpler although I guess that there are more appropriate mechanisms available (csvreader): string [] orgids[string]; foreach (line; range) { if (!line.empty) { auto row =

Re: trouble with associative Arrays

2024-01-20 Thread atzensepp via Digitalmars-d-learn
Thank you T for your hint. This worked perfectly On Saturday, 20 January 2024 at 14:44:49 UTC, H. S. Teoh wrote: Because .byLine reuses its line buffer. You want .byLineCopy instead. The section looks now simpler although I guess that there are more appropriate mechanisms available (csvreader

Re: Datetime format?

2024-01-20 Thread zoujiaqing via Digitalmars-d-learn
On Friday, 19 January 2024 at 00:22:48 UTC, H. S. Teoh wrote: On Thu, Jan 18, 2024 at 11:58:32PM +, zoujiaqing via Digitalmars-d-learn wrote: On Thursday, 18 January 2024 at 23:43:13 UTC, Jonathan M Davis wrote: > On Thursday, January 18, 2024 4:26:42 PM MST zoujiaqing via > Digitalmars-d-

Re: trouble with associative Arrays

2024-01-20 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 20, 2024 at 02:33:24PM +, atzensepp via Digitalmars-d-learn wrote: > Hello, > > I am new with D and want to convert a c program for a csv file manipulation > with exhaustive dynamic memory mechanics to D . > > When reading a CSV-file line by line I would like to create an associa

trouble with associative Arrays

2024-01-20 Thread atzensepp via Digitalmars-d-learn
Hello, I am new with D and want to convert a c program for a csv file manipulation with exhaustive dynamic memory mechanics to D . When reading a CSV-file line by line I would like to create an associative array to get the row values by the value in the second column. Although I save the row

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

2024-01-20 Thread Renato via Digitalmars-d-learn
On Saturday, 20 January 2024 at 13:07:39 UTC, Renato wrote: D overhead with the fastest compiler, LDC, compared with Rust: ``` 1.0 1.707627119 1.919527897 1.954595186 1.351342502 1.556217748 ``` Oh sorry, I only posted the rates for the Linux benchmark... On Mac M1, for some reason, D was a

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

2024-01-20 Thread Renato via Digitalmars-d-learn
Wow, fantastic feedback from lots of people, thanks so much! I will try to answer all points raised in the several answers I've got here since yesterday. On Saturday, 20 January 2024 at 01:27:50 UTC, H. S. Teoh wrote: I'm confused by the chained hashing of the digits. Why is that necessary

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

2024-01-20 Thread Siarhei Siamashka via Digitalmars-d-learn
On Saturday, 20 January 2024 at 01:27:50 UTC, H. S. Teoh wrote: On Sat, Jan 20, 2024 at 01:35:44AM +0100, Daniel Kozak via Digitalmars-d-learn wrote: [...] > Try addressing the points I wrote above and see if it makes a > difference. I have tried it (all of it) even before you wrote i