On Wed, Nov 19, 2003 at 09:12:01AM -0600, Jonathan Scott Duff wrote:
: On Tue, Nov 18, 2003 at 09:36:31PM -0800, Larry Wall wrote:
: > As for the original question that started this whole silly thread,
: > control structures that return values should probably be considered
: > some kind of generator, and have an explicit "yield"-like statement
: > that is orthogonal to "last" and such.  Such a generator would be
: > explicitly marked, as with "do {...}" above, only different.  The
: > inside of such a generator after the loop is the natural place
: > to say what happens if nothing in the loop "works".
: 
: I don't understand ...  Do you mean something like this?
: 
:       confer { 
:          for @a -> $x { ... } || beget @results;
:       }
: 
: where "confer" is the do-like marker and "beget" is the yield-like
: statement.  But why not this?
: 
:       for @a -> $x { ... } or do { ... }
: 
: I need an example.

Sorry, I wasn't being very clear.  It wouldn't be logically attached to
the outside of the for, but to the inside of the "confer", or whatever:

    @foo = gather {
        for @a -> $x { pick $x if mumble($x) }
        DEFAULT { @results }
    }

In which case you could also write:

    @foo = gather {
        DEFAULT { @results }
        for @a -> $x { pick $x if mumble($x) }
    }

But it might be clearer to put it outside:

    @foo = gather {
        for @a -> $x { pick $x if mumble($x) }
    } or @results;

On the other hand, putting the default up front is clearer if the
block is long.  Could even be something like:

    @foo = gather is default(@results) {
        for @a -> $x { pick $x if mumble($x) }
    }

Larry

Reply via email to