On Mon, Feb 12, 2007 at 09:38:45PM +0000, Smylers wrote:
: [EMAIL PROTECTED] writes:
: 
: > +++ doc/trunk/design/syn/S06.pod    Mon Feb 12 00:10:05 2007
: > +  Version: 69
: >  
: >  ... this does [work]:
: >  
: > +    my @data = 1,2,3;
: > +    my @tmp = eager @data;
: > +    @data <== grep { $_ % 2 } <== @tmp;
: > +
: > +Conjecture: these are probably impossible:
: > +
: > +    @data <== grep { $_ % 2 } <== eager @data;
: 
: Surely that's the form that folks will actually want?

Oh, I don't doubt it.  But people want the darnedest things sometimes...

The basic problem here is that mutable data is coupled to realtime
but lazy data is decoupled.

: With no supporting data at all I'm going to claim it's reasonably common
: to want to filter an array without any need to keep the original around;
: having the Perl 6 idiom for that involve a temporary array seems rather
: ugly, exactly the sort of awkwardness that Perl 6 is eliminating
: elsewhere.

The key phrase there is "without any need to keep the original around".
It's possible we can make the syntax work, but we have to be very
careful to be clear about the identity of the container and its data.
It's one thing to say

    $x = $x + 1;

where you know that the value of $x on the right can be read atomically
before $x gets clobbered on the left.  List assignment was a bad enough
problem in Perl 5, where things like

    ($a,$b) = ($b,$a)

have to be smart enough to copy to a temporary list for you.  In Perl 6
we have the additional factor that lists are lazy by default, so it's
not at all clear that

    @data = filter(@data)

starts reading from the right @data before left @data null the
array and starts reading the list on the right.

However, with <== we have something else going for us, which is that
we've defined the pointy end to basically be a binding rather than an
assignment.  So the trick to making the loop work is to not actually
have a loop.  In order to make it work, we essentially no longer
think of @data so much as a mutable value, but more as a bindable
container, and

    @data <== filter(@data)
    filter(@data) ==> @data

are really doing something more like

    my @data := filter(@data)

except that the latter doesn't actually work because the my clobbers
the variable name lexically.  So maybe we can make the loop work as
long as we guarantee the rebinding of the pointy end always happens
after the forking and binding of the blunt end.  Basically the blunt
end gives away the old variable to the subthread that is going to
filter it into the the list of values, and the sharp end rebinds the
name to a new container.

That's the only way I see it working right now.

Larry

Reply via email to