in reply to RFC: Simulating Ruby's "yield" and "blocks" in Perl
(I wanted to put this discussion into a separate post, think it will stir much controversy)
> argument signatures are lengthy in Perl
With the same technique like demonstrated in yield() one could simulate a syntac sugar function sig(), which would assign arguments from the upper caller sig( my($a,$b) ). sig could easily handle a lot more like:
- setting default values,
- check of obligatory parameters,
- handling named parameters,
- checking types
- automatic creation of API documentation.
- allowing docstrings
But the need to declare each variable to be lexical is cumbersome, who really wants to constantly repeat my ?
sub test { sig my $x='default', my $y, named => my $named, OPT; ... code ... }
so having a new keyword or syntax would facilitate things a lot
something like
... }sub test { mine $x='default', $y, named => $named, @OPT;
or even better
sub test { | $x='default', $y, named => $named, @OPT |; ... }
while I'm not sure if it's possible to use | w/o dangerous ambiguity.
Cheers Rolf
( addicted to the Perl Programming Language)
In Section
Meditations