在nim中传递函数

COM*_*COM 5 functional-programming parameter-passing nim-lang

我在Nim(版本0.10.2)中传递数学函数(procs)时遇到问题.

import math

var s1 = @[1.1, 1.2, 1.3, 1.4]
var s2 = map(s1, math.sqrt)
Run Code Online (Sandbox Code Playgroud)

我收到了错误

Error: 'sqrt' cannot be passed to a procvar
Run Code Online (Sandbox Code Playgroud)

如果我为sqrt编写一个包装器函数,它就可以正常工作.

proc fxn(x: float): float = math.sqrt(x)
var s2 = map(s1, fxn)
Run Code Online (Sandbox Code Playgroud)

我使用平方根和map作为示例,但最终我将sqrt(和其他数学过程)传递给另一个proc.有没有办法在不编写包装函数的情况下执行此操作?

def*_*ef- 5

有计划通过默认启用 pragma 并procvar为 C 导入的过程制作包装 procvar 来默认实现此功能:https://github.com/nim-lang/Nim/issues/2172