So, this idea hit me after musing on the difference between generic procedures and procedures with typedesc parameters. The only difference, in most circumstances, is that generic procedures can have only their type parameters evaluated before they are fully invoked, while procedures with type parameters must have all of their type parameters invoked (which is why closure iterators with typedesc parameters hardly work, if at all).
So, why not simply expand the generic procedure invokation syntax to not only partially apply types to procedures, but also apply other constants as well?
proc genericProc(T: typedesc, objA, objB:T): T {.closure.}=
return objA+objB
would then truly be equivalent to
proc genericProc[T](objA, objB:T): T {.closure.}=
return objA+objB
Not only that, but with this change, we would have easy, partially applied functions.
var twentyAdder = genericProc[int, 20]
var x = twentyAdder(2)
Or a more possible example, to get python-like iterators:
iterator range[ordType](start, stop: ordType, step = 1): ordType =
var i = start
while i <= stop:
yield i
inc(i, step)
var rangeIter = range[int,0,50] # Creates a range iterator with the arguments applied.
var x = rangeIter()
Implementation challenges aside (and I know that Araq and the other developers have enough on their plate as-is), is there anything wrong with this, concept-wise? I don't see any, aside from having to limit the generic invokation syntax to expressions that can be evaluated at compile time.