exceptionif-statementclauseoz

Missing else clause in Oz


The Oz Compiler launch an exception "Missing Else Clause" when I try to compile this code, can anybody tell me why? Here is my code :

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}}

In my opinion, there isn't a missing else clause in this code! My function will always return something.


Solution

  • In Oz language, all the variables need a uppercase. Lowercase is for atom's. So if you try to run your code with uppercases:

        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}}
    

    This will browse 0 as expected.