My understanding is that the template doesn't "return" a proc, rather it creates the code, at compile time, that the template says to generate. So by putting the template call inside your sorted call, you are actually creating a new proc definition in the middle of your call. If you call the template first, before the call to sorted, then it works, see: [https://play.nim-lang.org/#ix=26D2](https://play.nim-lang.org/#ix=26D2)
Does that still serve your purpose?
