On Sat, Jul 12, 2008 at 01:11:12AM +0200, Jonathan Worthington wrote: > This is consistent with my view of the specified Perl 6 semantics[1] for > closure handling. I translated Bob's Perl 5 example into PIR and put > newclosure where the Perl 6 specification would suggest to put it and it > produces the same output as the Perl 5 script. This is without doing > *any* newclosure calls prior to a call, just some when we are taking a > reference. > > Pm: I hope the PIR helps you understand Bob's example better. Notice > that we do newclosure whenever a block is referenced (where by block I > mean anything compiled down to a Parrot .sub) and the reference contains > the new closure, which makes sense because we're taking a closure > (recording a snapshot of it at that point) to invoke later.
Yes, the translation helps a lot. But what you came up with is almost exactly what I would expect PCT/Rakudo to be generating _now_ for this code example (modulo a few minor details). So I'm still left without a good PIR counterexample that shows that PCT as presently designed will generate code that won't work. :-( > Note that this doesn't give any great answers yet about what happens > when we do newclosure on a multi, but I think we can make that do > something sane (snapshot the lot, perhaps? Need to think about what > falls out of that...) This is one of the possible advantages of the 'capture' approach proposed previously -- we can ensure that the capture operation always comes directly from the outer sub, so when iterating through the Closures in a MultiSub it's easy to determine which ones need a capture without having to chase up the caller chain for each one. Thanks a bunch, Pm