At 3:37 PM +0000 1/18/02, Piers Cawley wrote:
>Michael G Schwern <[EMAIL PROTECTED]> writes:
>
>Hmm... making up some syntax on the fly. I sort of like the idea of
>being able to do
>
>     class File;
>     sub foreach ($file, &block) is Control {
>         # 'is Control' declares this as a control sub, which, amongst
>         # other things 'hides' itself from caller. (We can currently
>         # do something like this already using Hooks::LexWrap type
>         # tricks.
>
>         open my $fh, $file or die $!; POST { close $fh }
>        
>         while (<FILE>) {
>             my @ret = wantarray ?? list &block() :: (scalar &block());
>             given $! {
>                 when c::RETURN { return wantarray ?? @ret :: @ret[0] }
>             }
>         }
>     }
>
>This is, of course, dependent on $! not being set to a RETURN control
>'exception' in the case where we just fall off the end of the block.

I don't think you'll see $! being set to anything other than real 
errors. Larry may change that, but I'd doubt it. It's more a global 
status than anything else. Exceptions would go elsewhere, I'd hope.

I personally would like to see subs be taggable as transparent to 
yielding, so if you call a sub, and it calls a sub, that inner sub 
could yied out of the caller if the caller was transparent. Not, 
mind, that the scheme doesn't have issues, but...

>It's also dependent on being able to get continuations from caller
>(which would be *so* cool)

For some brainwarping version of cool. :)

>  > allow this:
>>
>>      File.foreach('/usr/dict/words') { print }
>
>Sounds plausible to me.
>
>>  or would the prototype be (&file, &block)?
>
>I prefer the ($file, &block) prototype.

I think it'll be ($file, &block), as that makes the most sense.

-- 

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                       teddy bears get drunk

Reply via email to