for some time now, a Wikipedia page is rumoring that languages
other than C++ and D can be used to achieve the effects of
template *meta*programming. That is, we can have our compilers
compute "functions," recursively, at compile time. The term
"function" here refers to an abstract mathematical thing and
their outcome is (the appearance of) a somewhat different program,
produced implicitly, at compile time.
(A standard example is factorial, showing two essential
characteristics of template metaprogramming, not usually
present in generics:
(1) have the compiler compute factorial(N), N being known at
compile time, by recursively instantiating a series of templates
(at compile time). Each instantiation in turn triggers the
instantiation of more of the same templates (with N decremented)
until finally the compiler finishes its work when it finds
a template specialized for the case N = 0.
(2) No function code is produced, just a result.)
I don't think this recursive template resolution has much to
do with generics in Eiffel, or has it?
Note that this is *not* just about good optimizers: these will
compute factorial(N), too, without anything generic in sight,
when N is known at compile time.
That's beside the point. Eiffel Compilers will still do as
they should and produce code of a feature named "factorial"
should that feature have been defined in a class. The C++
example leaves no function.
Also, can Eiffel generics be used for turning dynamic polymorphism
into static polymorphism?
I'll boldly correct the Wikipedia article should the above
negative result be correct.
- Georg
> for some time now, a Wikipedia page is rumoring that languages
> other than C++ and D can be used to achieve the effects of
> template *meta*programming.
No. Eiffel Generics can't do any meta programming.
The main difference between Eiffel Generics and C++ is that the
first are embedded into the language type system. The main
this works well is also one of the main differences to other
language: covariant redefinition of function arguments.
> Also, can Eiffel generics be used for turning dynamic polymorphism
> into static polymorphism?
This can be done, but it's not a feature of the template system
but based on the fact that Eiffel as a full system optimizing language
has much more information then a C++ compiler. So even non template
code can turning dynamic polymorphism into static polymorphism
OK
>> Also, can Eiffel generics be used for turning dynamic polymorphism
>> into static polymorphism?
>
> This can be done, but it's not a feature of the template system
> but based on the fact that Eiffel as a full system optimizing language
> has much more information then a C++ compiler. So even non template
> code can turning dynamic polymorphism into static polymorphism
I doubt this has much to do with the reach of compilers---IBM's
C++ compiler has been an incremental compiler for years, but even
this may not be important. But AFAIK, "virtual" in C++ forces
dispatching no matter what whereas both absence of "virtual"
and qualifying the method name will let programmers choose the
specific method at compile time.