t6137.nim 713 B

1234567891011121314151617181920212223242526272829
  1. discard """
  2. errormsg: "\'vectFunc\' doesn't have a concrete type, due to unspecified generic parameters."
  3. line: 28
  4. """
  5. type
  6. # simple vector of declared fixed length
  7. vector[N : static[int]] = array[0..N-1, float]
  8. proc `*`[T](x: float, a: vector[T]): vector[T] =
  9. # multiplication by scalar
  10. for ii in 0..high(a):
  11. result[ii] = a[ii]*x
  12. let
  13. # define a vector of length 3
  14. x: vector[3] = [1.0, 3.0, 5.0]
  15. proc vectFunc[T](x: vector[T]): vector[T] =
  16. # Define a vector function
  17. result = 2.0*x
  18. proc passVectFunction[T](g: proc(x: vector[T]): vector[T], x: vector[T]): vector[T] =
  19. # pass a vector function as input in another procedure
  20. result = g(x)
  21. let
  22. xNew = passVectFunction(vectFunc,x)