Re: Function Composition

2024-01-31 Thread atzensepp via Digitalmars-d-learn
On Monday, 29 January 2024 at 19:24:51 UTC, Inkrementator wrote: On Thursday, 25 January 2024 at 18:44:26 UTC, atzensepp wrote: However this works: ```d int delegate (int) td = (x) => compose!(f,g,g,f,g,g,f,g,g,f)(x); ``` While not a real function pointer, this might already fit your nee

Re: Function Composition

2024-01-29 Thread Inkrementator via Digitalmars-d-learn
On Thursday, 25 January 2024 at 18:44:26 UTC, atzensepp wrote: However this works: ```d int delegate (int) td = (x) => compose!(f,g,g,f,g,g,f,g,g,f)(x); ``` While not a real function pointer, this might already fit your needs. ```d alias td = compose!(f,g); ```

Re: Function Composition

2024-01-25 Thread atzensepp via Digitalmars-d-learn
On Thursday, 25 January 2024 at 12:19:47 UTC, Paul Backus wrote: On Thursday, 25 January 2024 at 08:25:02 UTC, atzensepp wrote: ```d int function(int) t = compose!(f,g,g,f,g,g,f,g,g,f); ``` This leads to: ``` gdc lambda4.d lambda4.d:28:25: error: template compose(E)(E a) has no value int f

Re: Function Composition

2024-01-25 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 25 January 2024 at 08:25:02 UTC, atzensepp wrote: ```d int function(int) t = compose!(f,g,g,f,g,g,f,g,g,f); ``` This leads to: ``` gdc lambda4.d lambda4.d:28:25: error: template compose(E)(E a) has no value int function(int) t = compose!(f,g,g,f,g,g,f,g,g,f); ``` Try using t

Re: Function Composition

2024-01-25 Thread atzensepp via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 21:34:26 UTC, user1234 wrote: 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

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

Function Composition

2024-01-24 Thread atzensepp via Digitalmars-d-learn
bda expressions I would like to write compose(f,g) ```dimport std.stdio; // Function composition: int f(int x) { return x*2;} ; int g(int x) { return x+2;} ; int delegate (int) compose( int delegate(int)second, int delegate(int)first) { return ((int i) => second(f