On Wed Dec 09 23:02:21 2009, jon@jrock.us wrote:
Show quoted text> * On Wed, Dec 09 2009, Ian Wells via RT wrote:
> > I find it annoying that I actually have to type
> >
> > method x(Item $arg) {
> > ...
>
> You don't have to type that. You can type "method x($arg?)". The ?
> modifier makes something optional.
Sorry, bad example on my part: take the 2 argument form,
method x($arg1, $arg2) {
if $arg1 is undef but $arg2 is not, we have the problem again. $arg1
cannot be specified as optional with '?' because MMS quite reasonably
barfs on
method x($arg1?, $arg2) {
Also,
method x(:$arg?) {
fails when called as
->x(arg => undef);
If what you want is a function that must take an argument which may be
undef, you have to use 'Item' or 'Maybe'.
If you want to specify a function that may accept a positional argument
but that argument, if specified, must not be undef, I'm not sure you can
do it at all.
I believe '?' should mean strictly 'may not be present in the arg list'.
'Can legitimately be undef' is a distinct property of arguments. My
preferred default - must be present, may be undef.