in reply to Re: why does push not default to $_? (simple)
in thread why does push not default to $_?
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!
DB<10> use Data::Dumper DB<11> print Dumper prototype "CORE::split" $VAR1 = undef; DB<12> print Dumper prototype "CORE::print" $VAR1 = undef; DB<13> print Dumper prototype "CORE::push" $VAR1 = '\\@@';
(²) But I don't know if it makes sense to push a global like $_ on the stack...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: why does push not default to $_? (simple)
by JadeNB (Chaplain) on Dec 05, 2008 at 22:30 UTC | |
by LanX (Saint) on Dec 05, 2008 at 22:59 UTC | |
by LanX (Saint) on Dec 06, 2008 at 02:00 UTC | |
by JadeNB (Chaplain) on Dec 07, 2008 at 18:13 UTC | |
by ikegami (Patriarch) on Dec 07, 2008 at 19:04 UTC | |
by LanX (Saint) on Dec 07, 2008 at 19:45 UTC |