Michael G Schwern writes: : Reading this in Apoc 4 : : sub mywhile ($keyword, &condition, &block) { : my $l = $keyword.label; : while (&condition()) { : &block(); : CATCH { : my $t = $!.tag; : when X::Control::next { die if $t && $t ne $l); next } : when X::Control::last { die if $t && $t ne $l); last } : when X::Control::redo { die if $t && $t ne $l); redo } : } : } : } : : Implies to me: : : A &foo prototype means you can have a bare block anywhere in the : arg list (unlike the perl5 syntax).
That is correct. : Calling &foo() does *not* effect the callstack, otherwise the : above would not properly emulate a while loop. Maybe it's transparent to caller but not to caller($n). I'm not sure how much of a problem this will be. Inside &block it's a closure, which carries a lot of the context you need already. Continuations may be overkill. : If that's true, can pull off my custom iterators? : http:[EMAIL PROTECTED]/msg08343.html : : Will this: : : class File; : sub foreach ($file, &block) { : # yeah, I know. The RFC was all about exceptions and I'm : # not using them in this example. : open(FILE, $file) || die $!; That's my $FILE = open $file || die; and so on. : while(<FILE>) { : &block(); : } : : close FILE; : } : : allow this: : : File.foreach('/usr/dict/words') { print } File.foreach('/usr/dict/words', { print }) or even (presuming the prototype is available for parsing): File.foreach '/usr/dict/words' { print } : or would the prototype be (&file, &block)? : : And would this: : : my $caller = caller; : File.foreach('/usr/dict/words') { : print $caller eq caller ? "ok" : "not ok" : } : : be ok or not ok? It has to be ok if mywhile is going to emulate a : while loop. I don't see why the default caller has to be caller(1). In any event, user-define control code will need to be able to get out of the way of the programmer's expectations. A return certainly needs to return from the surrounding lexical sub block, not from a mere bare block. Larry