Cadence Encounter 14.2 中 ::tcl::mathfunc::min 的参数数量错误

Wrong number of arguments for ::tcl::mathfunc::min in Cadence Encounter 14.2

我正在编写由 Cadence Encounter 版本 14.25(或 14.20,取决于我是查看日志文件还是启动时的启动画面...)执行的 Tcl 脚本。

嵌入式 Tcl 解释器的版本似乎是

% package require Tcl
8.5.9

我的脚本使用 ::tcl::mathfunc::min 函数,据我所知,该函数具有可变数量的参数,因此例如以下应该有效(它在我安装的 tclsh 中起作用,它具有版本 8.6.4):

% ::tcl::mathfunc::min 1 2 3
1

然而,当由 Encounter 执行时,情况似乎并非如此,它只适用于恰好两个参数:

% ::tcl::mathfunc::min 1 
too few arguments for math function "min"
% ::tcl::mathfunc::min 1 2
1
% ::tcl::mathfunc::min 1 2 3
too many arguments for math function "min"

为什么会这样?


引发的进一步调查:

遇到:

% info args ::tcl::mathfunc::min
"::tcl::mathfunc::min" isn't a procedure

太棒了! ...

我发现全局范围内有一个 min 命令具有相同的行为,但错误消息不同:

% min 1
wrong # args: should be "min x y"
% min 1 2
1
% min 1 2 3
wrong # args: should be "min x y"

两个(::min::tcl::mathfunc::min)都不包含在interp aliases的结果中。

如果你使用命令

info args ::tcl::mathfunc::min
info body ::tcl::mathfunc::min

在嵌入式和普通 Tcl 解释器中,您应该能够在两个地方看到构成 min 函数的参数和代码。如果它们(从您的调查来看很可能)不同,您可以用不同的名称创建自己的 min 函数,my_min 说,或者替换 ::tcl::mathfunc:: 命名空间中现有的 min 函数。注意:在 Tcl 8.5 和更高版本中,您在 ::tcl::mathfunc 命名空间中创建的函数可以在 expr 函数中使用。

Does the Tcl version reported by Encounter lie?

不一定。与 Tcl 定义的任何命令一样,可以重新定义 ::tcl::mathfunc::min。这样做不是一个好主意,但这样做是合法的……

Is Encounter's Tcl interpreter broken?

以次要方式。我不知道他们为什么这样做。

Does ::tcl::mathfunc::min only support two arguments in Tcl versions prior to 8.6?

$ tclsh8.5
% expr min(1,2,3,4,5)
1

看起来它在 8.5 中也能很好地处理许多参数。 (它在 8.4 中不存在;min 函数与一般的函数到命令调度机制同时引入。)

引入 ::tcl::mathfunc 的 TIP 有一些有趣的功能,您可以使用它来使用原始 ::tcl::mathfunc::min 而不是 Cadence 提供的两个 arg 版本。

它说:

Namespaces will be able to define their own math functions that are not visible outside those namespaces. If a namespace defines a function [namespace current]::tcl::mathfunc::f, then calls to f in expressions evaluated in that namespace will resolve to it in preference to ::tcl::mathfunc::f. Not only does this rule allow two extensions both to define functions f without collision, but it also allows an extension to override a builtin function such as sin."

参见:http://www.tcl.tk/cgi-bin/tct/tip/232.html

因此,在您自己的代码中,您可以通过在您自己的命名空间中提供适当的实现,简单地将 'min' 重新定义为普通代码。