Jonathan Scott Duff <[EMAIL PROTECTED]> writes:

> On Wed, Oct 30, 2002 at 02:25:02PM +0000, Piers Cawley wrote:
>> Given an acyclic graph of nodes, where a node has a method C<kids>,
>> returning a list of all the nodes it points to, is it the case that
>> the following code:
>> 
>>   sub descent($src, $dst) {
>>     when $src == $dst  { return $dst }
>>     when !$src.kids    { die }
>>     otherwise { 
>>       return ( $src, descent(any($src.kids), $dst))
>>     }
>>   }
>> 
>> will return a list of nodes making up a path between the nodes $src
>> and $dest? Or do I need to replace C<any> and C<die> with an
>> appropriate implementation of C<choose> and C<fail>?
>> 
>> It'd be really cool if superpositions had this kind of backtracking
>> behaviour, but I'm *so* not going to be surprised if it doesn't...
>
> Hey, that's neat. Although it looks like it returns the $src when there
> isn't a path. You probably want it to return undef or something.

Nah, it'll die when there isn't a path.

> Perhaps where you have "die" there should be something like
> $src.collapse or maybe just "return undef".

Well, traditionally you have 'fail' there, wants to be some kind of
exception, but I'm not entirely sure of what the semantics should
be.

You'd do C<pick(descent($src, $dst))> to get a path though, hopefully
it'd be resolved lazily. If not, the fact that we have continuations
means that it should be possible to implement a Grahamesque
'choose/fail' pair of funcs, but it'd be so much neater to do it with
superpositions... 

-- 
Piers

   "It is a truth universally acknowledged that a language in
    possession of a rich syntax must be in need of a rewrite."
         -- Jane Austen?

Reply via email to