FAQ

On 2014-02-03 01:55, Uri Guttman wrote:
On 02/02/2014 06:18 PM, Johan Vromans wrote:

sub foo( $p1, $p2 = 42 ) { ... }

Isn't the whole idea of a default value to get rid of having to bother
whether the argument was actually supplied?

If you have

sub foo( $p1, $p2 = undef ) { ... }

How often do you need to make a distiction between these two function
calls:

foo( $bar );
foo( $bar, undef );

If this is really important, then there are other ways.
wouldn't just an arity count be enough? optionals only work on fixed
count arity (slurpy last arg breaks it). today the best way to see if
you got all or partial args is to use @_ in a scalar context. so why not
some special var with that count? then you can easily see if $p2 was
really assigned undef from the caller or defaulted to it. i won't posit
the name or syntax of this var but it is only one var and not one per
optional var in the signature. i said special var so we don't have to
depend on @_ always being there (as discussed plenty in this thread).
My issue with that is, that it is positional, in stead of by name.

--
Ruud

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2021 Grokbase