Re: Function Composition

2024-01-24 Thread user1234 via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 21:30:23 UTC, user1234 wrote: On Wednesday, 24 January 2024 at 21:12:20 UTC, atzensepp wrote: [...] what a bummer! Have you tried https://dlang.org/phobos/std_functional.html#compose ? Well this violates the second requirement: the composition itself requi

Re: Function Composition

2024-01-24 Thread user1234 via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 21:12:20 UTC, atzensepp wrote: [...] what a bummer! Have you tried https://dlang.org/phobos/std_functional.html#compose ?

Re: Function Composition

2024-01-24 Thread atzensepp via Digitalmars-d-learn
Some progress: compose function needs to know type but templates help to create for different types. ```d import std.stdio; import std.container.array; // Function composition: int f(int x) { return x*2;} ; int g(int x) { return x+2;} ; double ff(double x) { return x*x;} ; double gg(double x

Re: Providing implicit conversion of - memory-safety

2024-01-24 Thread Siarhei Siamashka via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 09:28:57 UTC, Renato wrote: If you have "widespread" arithmetics which may overflow, something like https://dlang.org/phobos/core_checkedint.html is useful, yes, but in this case it's overkill. To make use of this, one needs to already anticipate an arithmetic

Re: Providing implicit conversion of - memory-safety

2024-01-24 Thread Renato via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 00:34:19 UTC, bachmeier wrote: On Tuesday, 23 January 2024 at 21:40:46 UTC, Renato wrote: While I can understand your frustration, it seems to me D is not to blame in this instance because the code is quite patently using unsafe constructs (D does not claim to

Function Composition

2024-01-24 Thread atzensepp via Digitalmars-d-learn
How is it possible to compose functions? I came up with following solution that is not satisfactory for two reasons: 1. the compose function should be argument agnostic here it is explicitly coded for (int) -> (int) 2. the composition itself requires additional lambda exp