With partial application and composition you can do cool things like this,
proc sum(x:int, y:int):int = x + y proc double(x:int):int = 2 * x var doubleSum10 = double & sum$|10 echo(doubleSum10(5)) # 30
Obviously a trivial example, but when you start to think of the function(procedure) as the primary unit of abstraction, it can get powerful and these are the basic building blocks.
My question is.. I don't have much experience with macros and have the feeling that my partial application operators could have been defined using one. I haven't figured out how to make it work yet. Anyone want to take a stab at it? Thanks.
My question is.. I don't have much experience with macros and have the feeling that my partial application operators could have been defined using one. I haven't figured out how to make it work yet. Anyone want to take a stab at it? Thanks.
It's been a while since I last thought about it, but in general macros will be up for tasks like this once a type API for them arrives. (I am currently reworking the whole evaluation engine that is used to evaluate macros...)
What should the parameters to this procedure look like?
proc params=(someProc: PNimrodNode; params: PNimrodNode) {.compileTime, raises: [EInvalidValue], tags: [].}
I can create a new proc like this
but I'm not clear how to add the parameters that this new proc is going to expect.
This macro system seems really exciting and powerful. Thanks!
You may want to take a look at this:
https://github.com/Araq/Nimrod/issues/402
Indeed, the missing part of the puzzle for implementing this solution is an "arity" type trait for procs.
Implementing type traits is extremely simple. There is only one function in the compiler that has to be modified:
https://github.com/Araq/Nimrod/blob/master/compiler/evals.nim#L907
and then the type trait has to be exported here:
https://github.com/Araq/Nimrod/blob/master/lib/pure/typetraits.nim
If you like to get your hands dirty, we'd love to accept patches for richer type APIs, but otherwise I could just go ahead and implement the arity type trait that is needed here.
zahary, I've got the "arity" proc working now. Did you imagine curry being a proc, template or macro?
My thought is to create a macro that returns a lambda. I think I can make this work......