Hello again!
As a way to help teach myself Nimrod, I've been working on porting a JavaScript math library that I wrote a while back. In doing this, however, I encountered a few problems.
1. Several of the functions work with points in the Cartesian coordinate system, and return another point. Ideally I'd like for this to be as an array, but I can't figure out what to specify as the return type. I've tried something like:
proc returnPoint(x : openarray[float], y : openarray[float]): openarray[float] =
...
return [1.1,2.2]
...but this gives an error.
Thanks in advance for any help!
1. Your example is confusing, are you accepting arrays of coordinates to join or just a single value? You can return arrays if you know the size in advance, otherwise you need to use sequences as mentioned:
proc returnPoint(x, y: float): array[2, float] =
result[0] = x
result[1] = y
proc returnPoints(x, y: openarray[float]): seq[array[2, float]] =
assert len(x) == len(y)
assert len(x) > 0
result = newSeq[array[2, float]](x.len)
for i in 0..high(x):
result[i][0] = x[i]
result[i][1] = y[i]
echo "single ", repr(returnPoint(2.3, 4.5))
echo "multi ", repr(returnPoints([1.0, 2.0, 3.0], [6.0, 7.0, 8.0]))