Newbie Question about Proc Declaration
Got an (I think) fairly simple question that should have a fairly simple answer, but I'm having a surprisingly hard time finding answers in the documentation.
Take this simple example of a procedure from Nim by Example:
proc zip[I, T](a, b: array[I, T]): array[I, tuple[a, b: T]] =
for i in low(a)..high(a):
result[i] = (a[i], b[i])
let nameAndAddresses = names.zip(addresses)
For reference, this example is included with an explanation of arrays, showing that a dynamic array's size must be passed to a procedure with its value(s).
All I want to know is what that [I, T] after the procedure name (zip) is. I suspect it indicates something about the return type (which is another array of variable size like it is being passed) but I just want to make sure I understand exactly what that means because I keep seeing it in other places and it's always a big question mark for me.
Any guidance?
Posted Aug 2, 2022, 2:52 AM UTC
It's a generic procedure that operates on any `array`. Nim's `array` are not dynamic array, they're static sized. `seq` is Nim's dynamic array. the `[I, T]` are generic parameters which bind to the `a` parameter's `[I, T]`
Thanks for the reply! I had to research a bit what "generic types" are in Nim but now I think I understand.