当我尝试编译此代码时,Oz 编译器启动异常“Missing Else Clause”,有人能告诉我为什么吗?这是我的代码:
declare
fun {Numero x y}
local NumeroAux in
fun {NumeroAux x y Acc}
if {And (x == 0) (y == 0)} then Acc
else
if y == 0 then {NumeroAux 0 x-1 Acc+1}
else
{NumeroAux x+1 y-1 Acc+1}
end
end
end
{NumeroAux x y 0}
end
end
{Browse {Numero 0 0}}
在我看来,这段代码中没有缺少 else 子句!我的函数总是会返回一些东西。
最佳答案
在 Oz 语言中,所有变量都需要大写。小写字母代表原子。 因此,如果您尝试使用大写字母运行代码:
declare
fun {Numero X Y}
local NumeroAux in
fun {NumeroAux X Y Acc}
if {And (X == 0) (Y == 0)} then Acc
else
if Y == 0 then {NumeroAux 0 X-1 Acc+1}
else
{NumeroAux X+1 Y-1 Acc+1}
end
end
end
{NumeroAux Y X 0}
end
end
{Browse {Numero 0 0}}
这将按预期浏览 0。
关于exception - Oz 中缺少 else 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26166548/