develooper Front page | perl.perl6.language | Postings from April 2005

Re: Closure/block/sub multiplier /// Win32 module for Perl6

Thread Previous | Thread Next
April 20, 2005 11:39
Re: Closure/block/sub multiplier /// Win32 module for Perl6
Message ID:
Larry Wall skribis 2005-04-20 11:25 (-0700):
> : It shouldn't treat a sub call differently, so that a called sub can in a
> : useful manner return a closure, which is then executed several times.
> : The same annoying special syntax can be found in perl 5's goto, that
> : can't go to a returned subref using "goto sub_that_returns_a_subref();".
> Doesn't this work in Perl 5?
>     goto &{sub_that_returns_a_subref()};
> If not, I'd say it's a bug.

Hm, it does. But it's not something I thought of when I needed it.

But it's one of those cases that have case-specific special syntax, and
I think it's best to avoid that.

The same thing goes for all those places where a variable is expected
that begins with $, like foreach. You can't easily use an lvalue sub.
The workaround is like your goto workaround:

    for ${\thatsub()} (1..10) { ... }

Although admittedly, I only encountered this when playing with a
non-readonly undef ;) (This is something I can recommend to anyone:
redefining true, false and undef leads to very spectacular code, where
anything's possible, and defined(undef) can be a true that stringifies
as "false".)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About