On Sat, Jul 25, 2009 at 06:50:12PM -0700, yary wrote:
: On Sat, Jul 25, 2009 at 2:04 PM, Patrick R. Michaud<pmich...@pobox.com> wrote:
: > On Thu, Jul 23, 2009 at 05:56:31PM +0200, TSa wrote:
: >> Hmm, it seems to be the case that the binding is defined to be a
: >> readonly binding to the variable. I consider this a bad thing.
: >> We should have my $x = 1; foo($x++,$x,$x++); to call foo(1,2,2)
: >> and not foo(1,3,2) or even foo(2,3,1). The capture creation for
: >> the foo call should be strictly left to right and capturing the
: >> value at that moment.
: >
: > ...except that captures don't capture values -- they form references.
: So we get a call to foo with three identical references to $x, which
: has the value "3", or "1"? That would be interesting. Or is capture
: meant to be lazy, and any postincrement is only called the first time
: foo dereferences that parameter? That would be very interesting! Which
: I would fully support in a language whose code I never had to
: maintain, but would not have to want to explain to anyone with a
: straight face.

Yes, I think think you're probably right that the correctest answer
to this will be to make the operation of binding $x++ trigger
the autoincrement lazily.  But I don't think you'd have to explain
anything for ordinary calls, since there is a one-to-one correspondence
between capture formation and binding, and the binding happens almost
immediately after capture composition (perhaps only notionally, since
capture composition an obvious optimizer target).  The only time it
would be difficult to explain is if you say something like:

    my $capture := \($x++);
    foo(|$capture); # increments $x
    bar(|$capture); # increments $x again

But perhaps \($x++) can be explained by analogy to { $x++ }.  It's
basically just a thunk, and the eventual binding and/or evaluation is
what prevents it from degrading into the morass of call-by-name-ness.
So it's very much like the thunks in

        $maybe ?? $x++ !! $y++

where you don't know which will be incremented until the implementation
of ??!! decides to run one thunk or the other.

It's also a strange way to name a monadic sort of relationship:

    my $capture := \($x++);
    $x = 0;
    |$capture xx *      # 0,1,2,3,4

Lately I've been thinking of lazy lists as Perl 6's cheap knockoff
of the idea of monads, modulo the appropriate amount of handwaving
(not to mention handwringing) over side effects.  Naming a lazy list
basically gives a name to the relationship between the consecutive
elements (where in the case of infix:<...> the new elements are
specifically defined in terms of the prior ones).  Yes, I'm ignoring
a bunch of cool type theory when I say that.  I'm hoping this will
make Perl 6 usable by non-geniuses without getting them into trouble
too terribly often.  :)

But certainly a lot of the get-into-trouble examples involve $x++,
so we'll need to be careful with that particular monad^Wside effect.


Reply via email to