Switch Prolog generation to printing out directly.

Before we were building up massive strings in memory, which is more
elegant/compositional but stupidly slow. This is uglier but works
quickly.