On 09/29/2010 09:32 AM, Denis Koroskin wrote:
On Wed, 29 Sep 2010 11:21:11 +0400, Norbert Nemec
<[email protected]> wrote:
IMHO, the test misses the point of compile-time metaprogramming: The
concept of "state" belongs to run-time. The D compile-time language is
purely functional and does not know a state or even an "order of
execution".
The conditions "cannot die or be eaten twice" are, at their core,
issues of state. Any "solutions" that claim to catch one of the last
three errors must either go beyond the purely functional nature of the
compile-time language or rely on additional constraints (e.g. no reuse
of previous elements)
Of course, one could devise a language with non-functional compile
time features, but within D, this would fundamentally break the
existing concept of meta-programming.
In D, there are templates (that are written in functional style, have no
state etc) and there is also CTFE that allows mutable state (but no
classes).
CTFE is restricted to pure functions, which means that it is effectively
syntactic sugar for something that could be done with pure functional
programming.
It may in fact be possible to solve the contest within a CTFE pure
function. It would then not be a challenge for the type system of the
language but it would demonstrate that D can run code at compile time.
Type violations are caught at compile-time even if the assignment itself
happens at run-time. This kind of protection is (out of principle) not
possible for killing or eating something twice, even with CTFE.