Open hugosenari opened 4 years ago
That would require making my(1, _, 3)
a macro, is that correct? Do you have an idea how could this be implemented, @hugosenari?
I'm newbie Not sure how, sorry.
But if I get your {.curry.}
right :
proc my(a, b, c: int): int {.curry.} = a + b + c
# creates
proc my(a: int) = proc (b: int) = proc (c: int): int
# it requires some standard PlaceHolder
type PlaceHolder = distinct bool
const _ = true.PlaceHolder
# and more proc defs
proc my(discarded: PlaceHolder) = proc(b: int) = proc(c: int) = proc(a: int): int
proc my(a: int) = proc(discarded: PlaceHolder) = proc(c: int) = proc(b: int): int
proc my(a: int) = proc(b: int) = proc(discarded: PlaceHolder) = proc(c: int): int
# ...
In JS
// Curried with placeholders.
curried(1)(_, 3)(2);
// => [1, 2, 3]
pytoolz/toolz propose use flip or partial for this, isn't fancy should work.
fn.py uses a more radical approach _
is for proc creation ie:
let my = _ + _ + _ # template(a, b, c: untyped): untyped =
In this case _
needs to be some kind of template :thinking:
Similar packages for other languages allow pass some constant, usually
_
, to ignore parameter in this call and expect it in next call.ie: