Larry Wall <[EMAIL PROTECTED]> writes:
> 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.
I think having the caller($n) stack work so that control structures
are transparent no matter where they came from is really, really
important. But we can do that right now by pulling Hooks::LexWrap type
tricks:
temp &CORE::GLOBAL::caller = { ... };
Problem solved. I'd just hoped it was something we'd not have to do
ourselves in the general case.
> : 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 }
Hmm... does this mean that control structures are just going to be
normal expression (a la Ruby)? Or are if/for/loop etc going to be
special cases? I really like them not being special cases, but I can
also see that having:
foreach foreach @a { ... } { ... }
be legal syntax would be very weird indeed. Hmm... going the whole
ruby hog would mean that:
{ ... }.foreach @ary;
would be valid. Hmm...
> : 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.
And caller has to 'lie' about its stack, because otherwise methods
that get called from within the loop that do caller($n) will get
confused.
--
Piers
"It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite."
-- Jane Austen?