在文件 linalg.lua
中我有这个函数声明:
function dot(A,B)
return sum(mult(A,B),2); -- sum along second dimension
end
然后在另一个文件中我有这些调用:
require 'linalg'
-- First fundamental Coeffecients of the surface (E,F,G)
local E = dot(Xu,Xu,2)
local F = dot(Xu,Xv,2)
local G = dot(Xv,Xv,2)
local m = cross(Xu,Xv,2)
local p = sqrt( dot(m,m,2) )
local n = div(m,concath(p, p, p))
-- Second fundamental Coeffecients of the surface (L,M,N)
local L = dot(Xuu,n,2)
local M = dot(Xuv,n,2)
local N = dot(Xvv,n,2)
我不明白的是:
Why the
dot
function is called with three arguments (being 2 always the last of them) if the function is declared with two arguments? Is it some Lua idiom?
代码在给出正确结果的系统中运行良好,现在我的任务是将其转换为 Python/Numpy。
最佳答案
引自 http://www.lua.org/pil/5.html
Parameters work exactly as local variables, initialized with the actual arguments given in the function call. You can call a function with a number of arguments different from its number of parameters. Lua adjusts the number of arguments to the number of parameters, as it does in a multiple assignment: Extra arguments are thrown away; extra parameters get nil.
所以简单地忽略了额外的参数,缺少的参数为零。是的。它是语言工作方式的一部分,非常适合使用。
关于lua - 为什么调用 Lua 中的这个函数需要一个额外的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23960404/