Nil ignores default value in parameter list #1245
Comments
Feels like a conflation of parameter defaults with container defaults. This Another issue crops up: what would this dispatch to: multi x { say "here" }
multi x ($) { say "there" }
x Nil If Perhaps it'd be better to make It is a bit weird tho that by merely assigning the variable to itself, without any other operations, you can change its value: sub f($a is copy = 42) {
say $a;
say $a = $a
}
f Nil;
# OUTPUT:
# Nil
# (Any) |
A proposed solution is to allow
|
Parameters are not assigned to, they are bound to, thus "signature binding". The parameter default is also bound. The resetting behavior of Another difference is that the While we use the word "default" for both, they also look different ( Another consideration is this:
Meaning the feature would be useless in the case of a type constraint on a parameter. I fear this would then lead to a push to make A change to make
Given I implemented both kinds of default, I'm about the worst person to comment on whether it's surprising, because of course it isn't to me. :-) That said, given the two look different in code anyway, the only thing I can see that relates them is the use of the word "default".
Could one not make the very same argument about a
This is an interesting case because here there is a
I already saw somebody note that this could cause |
Based on the discussion above, I'm closing this ticket. |
Currently Nil is assigned to the parameter even though a default value is assigned.
This is at best surprising and may lead to undefined behaviour of a program as a default value is meant to replace and as such avoid undefined values in the routine. Using the default value when
Nil
is assinged would avoid that problem.One complication would be a
is raw
parameter that got a default value (what in itself may be problematic). Asis raw
is meant to pass whatever is provided as an argument to the routine. In this caseNil
should be passed on even if there is a default value.see discussion at https://irclog.perlgeek.de/perl6/2017-11-10#i_15429754
The text was updated successfully, but these errors were encountered: