Search code examples
functionrecursionozmozart

Mozart Oz function that returns nothing but executes several instructions


The question is in the title, how do I create a function which doesn't provide a returned value, but could execute several instructions?

For example:

declare
fun {doStuff Tree}
   case Tree
   of bTree(T left:leaf right:leaf) then {Browse Tree}
   [] bTree (T left:T1 right:T2) then {doStuff T1} {doStuff T2}
end

In this case I want to call recursively the function doStuff but I can't since it's set to return the last instruction, I just get an error. But when I remove {doStuff T2} it compiles.


Solution

  • Such functions are called "procedures" in Oz. To define a procedure, use the "proc" keyword:

    proc {DoStuff Tree}
        ...
        {DoStuff T1} {DoStuff T2\
    end
    

    Note: The names of functions and procedures must start with an uppercase letter.