Austin Hastings writes: > Perhaps this is one of those places where properties can help. Instead of > having BEFORE, REALLY_BEFORE, NO_I_MEAN_REALLY_BEFORE, DONE, MOSTLY_DONE, > PARTIALLY_DONE, WELL_DONE, DONE_AND_PROCESS_SPACE_ALMOST_RECLAIMED, etc., we > could simply use some ordering properties: > > # Each "broad class" of upcased block is an execution group. The entries > # in each execution group are not guaranteed to run in any particular order, > # and in fact may run in parallel on a multithreaded perl.
Would you guys cut that out! Nothing's running in parallel unless I tell it to! Or peraps, Nothing's running in parallel if I tell it not to! In either case, it could be an easy, global pragma overridable locally[1]. If I'm printing debug messages during compilation, say: BEGIN { print "Before load\n"; } use SomePackage; BEGIN { print "After load\n"; } I don't want to be getting: BefAfter load ore load Obviously this is a pathological case, due to the restriction immediately below, but you can extrapolate to more complex things. > # However, blocks in the same source file are guaranteed to run in order of > # occurrence. (Since they're catenated, basically.) > # > # Thus, all "BEGIN" blocks in a file are effectively catenated and added to > # an overall "BEGIN" execution group. All the separate BEGIN entries have > # the same initial priority(10), so they will run in whatever order suits > # the P6 runtime. > # > # The C<go> property introduces changes to the execution group and/or > # priority of the block in question. (Note that different priorities may > # be attached to different blocks within the same file. Doing so creates > # separate execution bundles, and breaks any guarantees about order of > # execution.) > # > package OtherPackage; > BEGIN will go <first> { > print "first!"; > } And what's with all the weird notation? Perl 6 naturally supports this without adding new syntax: BEGIN :first {...} BEGIN :priority(5) {...} I trust that these pairs will be somehow moved into their pair position after the block by Perl, since named args have to come after positional args. There are a lot of functions that take blocks, and writing: BEGIN { print "I am here: [ "; print( @data ==> map { .join(',') } ==> join ';'); print " ]\n"; } :first; Seems to horribly violate end weight. > package SomePackage; > BEGIN will go <after OtherPackage::BEGIN> { > print "Second!"; > } > > END will go <priority 5> { > print "End block with early priority"; > } > > package ThirdPackage; > END will go <group BEGIN before SomePackage::BEGIN> { > print "I feel really out of place!"; > } > > Comment? As far as the execution groups, no, I don't think so. In particular, because I want: use SomePackage; BEGIN { SomePackage::foo(); } to work without doing some unnecessarily verbose encantation on that BEGIN. On the other hand, using a flag to indicate that you want a particular END to be [one of] the very last may be the right way to go. It's uncommon enough that the people who need it will be more than willing to look it up. Luke [1] And that's really just to make those happy who are efficiency-crazy. I have a strong aversion to automatic threading, and I don't care if it takes more than one line to put it in. In any case, I want control of my threads, otherwise my sweatshirt's going to come out raveled.