2014-10-02 54 views
1

當我試圖編譯這段代碼時,Oz編譯器啓動了一個異常「Missing Else Clause」,有人可以告訴我爲什麼嗎?這裏是我的代碼:在Oz中缺少else子句

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子句!我的功能將永遠返回一些東西。

+1

終於發現錯誤..我忘了Oz中的變量必須以大寫字母開頭......但我不明白爲什麼Oz編譯器會說「Missing Else Clause」而不是像「變量必須以大寫字母」... – anpar 2014-10-02 18:31:43

回答

1

在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預期。