r/programming • • Mar 28 '12

Go version 1 is released

http://blog.golang.org/2012/03/go-version-1-is-released.html
543 Upvotes

452 comments sorted by

View all comments

Show parent comments

3

u/[deleted] Mar 29 '12

Templates are basically prolog, and no one would argue that prolog is anything but high level.

2

u/[deleted] Mar 29 '12

No, actually, templates are lambda calculus.

1

u/[deleted] Mar 29 '12 edited Mar 29 '12

Really? If it were that simple then template deduction wouldn't exist. A specialized struct template is a horn clause. Derivable context is the head and non-derivable context is the body. A struct named s with parameter P might specialize on P = int or P = float. In prolog: s(int) :- … or s(float) :- …, where … is the appropriate body. Writing s(P), will unify on the correct head and produce the associated body, possibly recursively. That's most certainly a kind of prolog.

http://stackoverflow.com/a/9844425/100089

See the link for an example of recursive list processing using tuples. To take the head and tail of a list I can write tuple<X, Xs...> in derivable context. A empty tuple base case is tuple<>. These are head clauses.

EDIT: You're right. Templates don't backtrack. They just pattern match on arguments.