Luis Quesada wrote:
P.S. Of course, you could give up on using records and use objects or
functions instead. An object O is more than capable of calculating
O(x1) if and only if someone requests it, then caching it for future
use, which is essentially how Robert is trying to use lazy trees. Or
so it seems to me.

What I like of the solution using open records is that it is declarative. So, there is no problem when binding several branches concurrently.

But your solution has a drawback: you cannot restrict the set of branches. If the user asks for T^foo, and there is no branch 'foo' in the tree, you're in trouble. You can actually wrap your solution behind a function that checks for valid branches, and never makes the record public:

fun {MakeTree IsValid Create}
   T=tree(...)
in
   thread
      for I in {RecordC.monitorArity T} do T.I={Create I} end
   end
   fun {$ I}
      if {IsValid I} then T^I else
         raise invalidBranch(I) end
      end
   end
end

You could be even more paranoid, and return !!(T^I).  You never know ;-)

Cheers,
raph

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

Reply via email to