Benjamin L. Russell wrote:
Thank you; that makes sense.  So, if I understand
correctly, essentially, it's syntactic sugar for the
equivalent tail-recursive procedure.

But that brings up the question of whether I can make
a procedure explicitly non-tail-recursive.  E.g., if
the following piece of code

Z = X|{SMerge Xr Ys}

is always automatically converted to the following
piece of tail-recursive code

local Temp  in
 Z = X|Temp
 {SMerge Xr Ys Temp}
end

This conversion is perfectly correct in Oz. We chose this one instead of the non-tail-recursive one (below), because tail recursion performs better in most cases (in terms of time and space performance).

local Temp in
   {SMerge Xr Ys Temp}
   Z = X|Temp
end

then how can I write the code so that it runs in a
non-tail-recursive manner?

Don't nest expressions inside lists or records, but evaluate them explicitly before making the list or record. For instance, the expression X|{SMerge Xr Ys} can be written

   local Zr={SMerge Xr Ys} in X|Zr end

raph

_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to