Perl Monk, Perl Meditation | |
PerlMonks |
Re^2: why does push not default to $_? (simple)by LanX (Saint) |
on Dec 05, 2008 at 09:41 UTC ( [id://728237]=note: print w/replies, xml ) | Need Help?? |
Am I understanding you right, the prototyope mechanism of builtins like push can't distiguish between missing parameters and empty parameters. But some special functions like "print" and "splice" have a proper non-prototype-based interface? (*)
I'm not really missing that feature, it's just a meditation about design and orthogonality. IMHO, it would be much easier to prog if perl had more axiomatic rules instead of a bunch of special exeptional cases. Something like "if the last obligatory list @ or scalar $ in a prototype is ommitted in the code, $_ will be included instead throwing an error". Or as more flexible approach "you can use "@_" and "$_" in prototypes to flag parameters which default to $_ if missing" ² anyway, perl6's solution to flag these functions with a trailing . and making them methodes of an invisible $_ seems reasonable! (eg .print; .push @a;) Cheers Rolf (*) Must be! That's why prototype returns undef for print and split, showing they are not overridable!
(²) But I don't know if it makes sense to push a global like $_ on the stack...
In Section
Seekers of Perl Wisdom
|
|