exception - Oz 中缺少 else 子句

标签 exception if-statement clause oz

当我尝试编译此代码时,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/

相关文章:

java - 如何在原始堆栈跟踪位置集中记录异常?

java - Android 2.1 和 HTC Desire : Is there a bluetooth problem?(CorruptedStreamException)

c# - Prism 应用中的异常处理策略

mysql - Solution Compatible Oracle and MySQL for LIMIT clause

join - 如何在FSharp查询表达式中编写带有复合键子句的联接?

ruby-on-rails - 如何在 Ruby 中正确使用 guard 子句

PHP:尝试/捕获失败

python - 和/或在 python if 语句中的简写

php - 根据从下拉菜单中选择的值,不输出正确的回波

javascript - 在 JavaScript If/else 语句中,如何根据条件呈现脚本标签?