@mratsim, it looks we posted at the same time and I missed your answer. Much
better your second solution. Thanks.
Your pt proc is a generic proc, that is when you call it with different types,
then for each type an instance is created.
For t1 you call it with int arguments, so an instance for ints is created.
For t2 and t3 first argument is a float, so a float instance is created, the
other literals are
@Stefan_Salewski is right
Change to that
proc pt*[N:SomeNumber](x, y, z:N):tuple[x,y,z:float] =
return (x: x.float, y: y.float, z: z.float)
let t1 = pt(0,0,0)
let t2 = pt(0.1, 0, 0)
let t3 = pt(0.1, 0.3, 0)
let t4 = pt(0.0, 0.3, 0) #<-
echo
Thanks Stefan. Understood.
I fixed it with:
proc pt*[N1,N2,N3:SomeNumber](x:N1, y:N2, z:N3):tuple[x,y,z:float] =
Run
Why the following code is failing?
proc pt*[N:SomeNumber](x, y, z:N):tuple[x,y,z:float] =
return (x: x.float, y: y.float, z: z.float)
let t1 = pt(0,0,0)
let t2 = pt(0.1, 0, 0)
let t3 = pt(0.1, 0.3, 0)
let t4 = pt(0, 0.3, 0) #<- Why is this