Re: Compile Time Fun Time

2019-02-25 Thread Paul Backus via Digitalmars-d-learn
On Monday, 25 February 2019 at 06:51:20 UTC, Yevano wrote: I am writing a domain specific language of sorts in D for the lambda calculus. One of my requirements is that I should be able to generate expressions like this: new Abstraction(v1, M) like this: L!(x => M) A word of caution: this

Re: Compile Time Fun Time

2019-02-25 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 25 February 2019 at 08:24:06 UTC, Yevano wrote: One thing. The variables were reversed. Fixed by changing these lines. auto result = new Abstraction(vars[$ - 1], f(vars)); foreach_reverse(e; vars[0..$ - 1]) { result = new Abstraction(e, result); } Yup. I assumed that didn't ma

Re: Compile Time Fun Time

2019-02-25 Thread Yevano via Digitalmars-d-learn
One thing. The variables were reversed. Fixed by changing these lines. auto result = new Abstraction(vars[$ - 1], f(vars)); foreach_reverse(e; vars[0..$ - 1]) { result = new Abstraction(e, result); }

Re: Compile Time Fun Time

2019-02-25 Thread Yevano via Digitalmars-d-learn
On Monday, 25 February 2019 at 07:40:51 UTC, Simen Kjærås wrote: The simple scalable version - just change maxArgs to a number that suits you: It works! Thanks. Didn't know about static foreach.

Re: Compile Time Fun Time

2019-02-24 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 25 February 2019 at 06:51:20 UTC, Yevano wrote: This only works for at most 3 parameter delegates. If I want to add more, I have to linearly add more static ifs in the obvious way. However, I believe I can make this function scalable using string mixins and other magic. Any insight i

Re: Compile Time Fun Time

2019-02-24 Thread Yevano via Digitalmars-d-learn
On Monday, 25 February 2019 at 07:03:21 UTC, Nicholas Wilson wrote: import std.traits; Abstraction L(alias f)() { alias Args = Parameters!f; Args v; foreach(i; 0 .. v.length) v[i] = new Variable; auto _f = f(v); auto abstraction = new Abstraction(v[$-1],_f); foreach

Re: Compile Time Fun Time

2019-02-24 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 25 February 2019 at 06:51:20 UTC, Yevano wrote: I am writing a domain specific language of sorts in D for the lambda calculus. One of my requirements is that I should be able to generate expressions like this: new Abstraction(v1, M) like this: L!(x => M) It is common to want to w