如何从 Nim 中的过程 return 数组

How to return an array from a procedure in Nim

我正在尝试 return 从 Nim 中的一个过程中获取一个数组。我的程序如下,

proc signGen*(n, f0, fs, multi=true): array[cdouble]
 =                                                 
  var signal: array[0..n, cdouble]
  if multi == true:
    for f in 1..int(n/2):
      for s in 1..n:
        signal[s] = sin(f*(2*PI)*s/fs)
        signal[s] += cos(f0 * f *(2*PI) * s / fs)
  else:
    for s in 1..n:
      signal[s] = sin(f*(2*PI)*s/fs)
  return signal

我收到以下错误,

 ~~> nim c -r src/stft.nim                        1 
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: used config file '/etc/nim/config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: stft [Processing]
Hint: lib [Processing]
Hint: math [Processing]
Hint: bitops [Processing]
Hint: macros [Processing]
/home/ruste/Development/nim_devel/projects/stft/s
rc/lib.nim(3, 44) Error: array expects two type para
meters 

感谢任何解决此问题的帮助。

Nim中的数组是指固定大小的数组。所以你需要提供一个编译时常量大小:array[4, cdouble].

如果你想要一个可变大小的数组,你需要使用 seq :

proc signGen*(n, f0, fs, multi=true): seq[cdouble]=