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?