Mozart Function parse error

1k Views Asked by At

when am trying to run this factorial function on this Mozart online complier

i got parse error !

    declare
fun {Fact N}
   fun{Aux N Nmax FactNminus1}
      if N>Nmax then nil
      else (FactNminus1*N)|{Aux N+1 Nmax FactNminus1*N}
      end
   end
in
   {Aux 1 N 1}
end
{Browse {Fact 4}}

how i can run this piece of code on this online compiler !

1

There are 1 best solutions below

0
On BEST ANSWER

Your code is an Oz script. It can be used in the interactive Mozart IDE (Emacs).

The online compiler expects an Oz program, i.e. a functor definition. Try this code:

functor
import
   Application
   System
define
   fun {Fact N}
      fun{Aux N Nmax FactNminus1}
         if N > Nmax then nil
         else (FactNminus1*N)|{Aux N+1 Nmax FactNminus1*N}
         end
      end
   in
      {Aux 1 N 1}
   end

   {System.show {Fact 4}}
   {Application.exit 0}
end