please help me, what I'm doing wrong?
type tup = tuple[x:int, y:proc(a:int), z:int]
proc mm(a:int): int = a + 1
const ma:tup = @[1, mm, 2]
nim tells: Error: type mismatch: got (proc (a: int): int{.gcsafe, locks: 0.}) but expected 'int literal(1)'
This code compiles
type tup = tuple[x:int, y: proc(a:int): int, z:int] # mm return type didn't match
proc mm(a:int): int {.closure.} = a + 1 # mm is closure
const ma:tup = (1, mm, 2) # Tuple literal is just `(...)`. `@[...]` is a sequence literal.
thanks a lot, now it works
type tup = tuple[x:int, y: proc(a:int):int, z:int]
type setup = seq[tup]
proc mm1(a:int): int {.closure.} = a + 1
proc mm2(a:int): int {.closure.} = a + 2
const ma:setup = @[(1, mm1, 2),(3, mm2, 4)]
echo ma[0].y(ma[0].x)
echo ma[1].y(ma[1].z)
I may be wrong, but procvars are closures by default. If you don't want them to be closures, here's another way:
type tup = tuple[x:int, y: proc(a:int): int {.nimcall.}, z:int]
proc mm(a:int): int = a + 1 # nimcall
const ma:tup = (1, mm, 2)