2

In this article, the writer asserts:

...the program did show that the template instantiation mechanism is a primitive recursive language that can perform nontrivial computations at compile time.

I found this rather interesting, as I help to teach a class in Theory of Computation which delves into the theory of primitive recursive functions. However, I was under the impression that Template Metaprogramming was Turing-complete, which is a strictly stronger statement than to say that it is primitive recursive...And after all, it is not very difficult to create a template metaprogram which fails to halt.

Am I missing something? Is Template Metaprogramming a strictly primitive recursive language, or am I correct in believing it to cover a wider range of programs?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Dan M. Katz
  • 337
  • 2
  • 13
  • Thanks for the edits Cody...I'll try to be cleaner next time :) – Dan M. Katz Dec 22 '11 at 06:52
  • While being primitive recursive, C++'s template metaprogramming is also Turing-equivalent. – Gabe Dec 22 '11 at 06:53
  • Correct me if I am wrong, but I believe that to say that a language is "primitive recursive" implies that you can program a very certain class of functions (namely those which do not utilize unbounded loops). Primitive recursive languages guarantee that any program written in them will halt...Of course, a Turing-equivalent language can also run a primitive recursive function, but that's besides the point. – Dan M. Katz Dec 22 '11 at 06:56
  • I could be wrong, but I'm not aware of a definition for "primitive recursive language", so I assumed that it means "a language in which primitive recursive functions can be written". If it means "a language in which *only* primitive recursive functions can be written", then I am indeed wrong. – Gabe Dec 22 '11 at 07:14

2 Answers2

3

I believe you just read too much into the text, and the "primitive" is not meant as "primitive recursive", but rather it is a "recursive language" (which sounds odd, I'd call describe that as a functional language, but never mind), which is primitive.

If you look at TMP as a functional language, it is not a very sophisticated one; thus, it is a primitive one.

But you are correct, TMP certainly is Turing-complete.

I doubt many people have heard of primitive recursive languages, and so this is just an unfortunate choice of words.

jalf
  • 243,077
  • 51
  • 345
  • 550
1

Unruh's program only demonstrated primitive recursion, that is, looping (I was actually present when this happened!). However it was immediately recognized that full recursion was supported (because indeed the implementation did not do tail rec optimisation).

Yttrill
  • 4,725
  • 1
  • 20
  • 29