My first email to Walter, ever
John Colvin
john.loughran.colvin at gmail.com
Sun Jul 7 05:48:38 PDT 2013
On Sunday, 7 July 2013 at 12:27:02 UTC, Peter Alexander wrote:
> On Sunday, 7 July 2013 at 03:03:03 UTC, Andrei Alexandrescu
> wrote:
>> Terrible. If you have conditionals, iteration, functions, and
>> objects
>> in D's straight programming support, you should have
>> conditionals,
>> iteration, functions, and objects in D's metalanguage.
>
> :-(
>
> template allSatisfy(alias F, T...)
> {
> static if (T.length == 0)
> {
> enum allSatisfy = true;
> }
> else static if (T.length == 1)
> {
> enum allSatisfy = F!(T[0]);
> }
> else
> {
> enum allSatisfy =
> allSatisfy!(F, T[ 0 .. $/2]) &&
> allSatisfy!(F, T[$/2 .. $ ]);
> }
> }
>
> Still looks like half-assed functional programming to me.
>
> Where's the iteration? Why can't I write this?
>
> template allSatisfy(alias F, T...) {
> foreach(t; T)
> if (!F!(t))
> return false;
> return true;
> }
>
> (Those are rhetorical questions btw, before anyone links me to
> a D tutorial).
>
> We're almost there with CTFE, but CTFE can only run functions
> that could run at runtime. In a crazy world where types were
> first class objects, stuff like this would be feasible. Or
> perhaps we just need a compile-time metalanguage that allows
> things like this to be run with CTFE?
So what you're effectively asking for is for templates to be
compile-time functions where types are first class variables.
I would love that.
More information about the Digitalmars-d-announce
mailing list