> But, as Luke pointed out, some of the other syntax required to make 
> that work is isn't particularly friendly:
> 
>      coro pre_traverse(%data) {
>          yield %data{ value };
>          yield $_ for <&_.clone(%data{ left  })>;
>          yield $_ for <&_.clone(%data{ right })>;
>      }
> 
> If I work backwards, the syntax I'd _want_ for something like that 
> would be much like Luke proposed:
> 
>      sub pre_traverse(%data) is coroutine {
>          yield %data{ value };
>          pre_traverse( %data{ left  } );
>          pre_traverse( %data{ right } );
>      }
> 
> ... where the internal pre_traverses are yielding the _original_ 
> pre_traverse.  Whoa, though, that doesn't really work, because you'd 
> have to implicitly do the clone, which screws up the normal iterator 
> case!  And I don't immediately know how to have a syntax do the right 
> thing in _both_ cases.
> 
> So, if I have to choose between the two, I think I'd rather iteration 
> be easy than recursion be easy.  If lines like
> 
>         yield $_ for <&_.clone(%data{ left  })>;
> 
> are too scary, we might be able to make a keyword that does that, like:
> 
>      sub pre_traverse(%data) is coroutine {
>          yield %data{ value };
>          delegate pre_traverse( %data{ left  } );
>          delegate pre_traverse( %data{ right } );
>      }
> 
> Maybe.  But in truth, that seems no more intuitive than the first.

Well, at least it's not using all those fancy features that will scare
off non-gurus.  But I think that instead of something declared coro
I<returning> a coroutine iterator, why not just make it one (which I
believe was Damian's original intent)?

    for <&foo> {...}

A subroutine could gladly return one of these iterators in place of a
different kind of iterator (or iterable structure).  

The problems come when passing arguments to it.  For that, you can use
a coroutine factory, or you can do it this way:

    for < coro { foo($a, $b) } >   {...}

We might need some shorthand for that... but probably not.

This is interesting:

    my $coro = coro { foo($a, $b) };
    $coro();

Calls foo($a, $b) without becoming a coroutine.  I don't know whether
this is useful or just strangely counter-intuitive.

Luke

Reply via email to