I appreciate all the solutions.  I had come up with a solution myself based on some slight modifications to Luis' original reply but without the need for reflectArity or monitorArity because in my particular case, I know ahead of time the set of potential branches and so I created a thread that blocked until that branch was needed.  The downside there of course is that I'll end up with dozens (probably hundreds) of blocked threads that may never get unblocked.  Some of the later solutions seem like cleaner approaches and so I think I change to using monitorArity.

As for the issue of creating branches that shouldn't exist, that actually wouldn't be a big negative in the problem I'm working on since those branches would just get appropriately terminated as leaf nodes with no data to store and the results would still be consistent.  I imagine there are other problems where trivial such leaves are not a problem (assuming of course that the leaves don't so outnumber the valid branches that you run into problems with the overall size of the tree).  Sometimes its nice to not have to do extra sanity checking (and sometimes its vitally important :).

Rob


On 3/15/06, Raphael Collet <[EMAIL PROTECTED]> wrote:
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

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

Reply via email to