Skip Menu |
Report information
Id: 126417
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: lloyd.fourn [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] proto signature default values don't work (NYI?)
To: rakudobug [...] perl.org
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Date: Wed, 21 Oct 2015 20:50:00 +1100
Download (untitled) / with headers
text/plain 375b
The design docs don't specifically say it's meant to work but implies it by saying that shared traits can be set in the proto and default value ~~ trait (to me).

class A {
    proto method foo($x = 'foo') {*}
    multi method foo($x) {
        $x.say;
    }
}

A.foo(); #!> none of these signatures match

If specifying a default in a proto is wrong it should carp I guess.
To: "Lloyd Fournier (via RT)" <perl6-bugs-followup [...] perl.org>
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Subject: Re: [perl #126417] [BUG] proto signature default values don't work (NYI?)
Date: Wed, 21 Oct 2015 14:31:00 +0200
Download (untitled) / with headers
text/plain 1019b
¢ Show quoted text
> On 21 Oct 2015, at 11:50, Lloyd Fournier (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by Lloyd Fournier > # Please include the string: [perl #126417] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=126417 > > > > The design docs don't specifically say it's meant to work but implies it by > saying that shared traits can be set in the proto and default value ~~ > trait (to me). > > class A { > proto method foo($x = 'foo') {*} > multi method foo($x) { > $x.say; > } > } > > A.foo(); #!> none of these signatures match
Looks like the { * } is overriding anything you’re specified in the signature. Putting anything else in there, does seem to do the right thing. But there is no easy way to dispatch to the other candidate (that I know of). Show quoted text
> If specifying a default in a proto is wrong it should carp I guess.
Perl 6 doesn’t carp (afaik): but yeah, it should fail :-) Liz
CC: "Lloyd Fournier (via RT)" <perl6-bugs-followup [...] perl.org>
To: Elizabeth Mattijsen <liz [...] dijkmat.nl>
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Subject: Re: [perl #126417] [BUG] proto signature default values don't work (NYI?)
Date: Thu, 22 Oct 2015 00:33:53 +1100
Download (untitled) / with headers
text/plain 1.5k
lizmat++
Fail is a good word. I didn't want to have to write throws an exception :o|

I don't totally get the concept of { * } so I won't comment whether defaults working makes sense or not but it's interesting to note that coercions don't work in a similar fashion:

class A {

    proto method foo(Int() $x) {*}
    multi method foo($x) {

         $x.WHAT.say; #-> Str

    }
}

A.foo('1');

$x gets coerced but the coerced value doesn't travel downstream.

On Wed, Oct 21, 2015 at 11:31 PM, Elizabeth Mattijsen <liz@dijkmat.nl> wrote:
Show quoted text
¢
> On 21 Oct 2015, at 11:50, Lloyd Fournier (via RT) <perl6-bugs-followup@perl.org> wrote:
>
> # New Ticket Created by  Lloyd Fournier
> # Please include the string:  [perl #126417]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org/Ticket/Display.html?id=126417 >
>
>
> The design docs don't specifically say it's meant to work but implies it by
> saying that shared traits can be set in the proto and default value ~~
> trait (to me).
>
> class A {
>    proto method foo($x = 'foo') {*}
>    multi method foo($x) {
>        $x.say;
>    }
> }
>
> A.foo(); #!> none of these signatures match

Looks like the { * } is overriding anything you’re specified in the signature.  Putting anything else in there, does seem to do the right thing.  But there is no easy way to dispatch to the other candidate (that I know of).


> If specifying a default in a proto is wrong it should carp I guess.

Perl 6 doesn’t carp (afaik): but yeah, it should fail  :-)


Liz

RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 952b
On Wed Oct 21 06:34:47 2015, lloyd.fourn@gmail.com wrote: Show quoted text
> lizmat++ > Fail is a good word. I didn't want to have to write throws an > exception :o| > > I don't totally get the concept of { * } so I won't comment whether > defaults working makes sense or not but it's interesting to note that > coercions don't work in a similar fashion: > > class A { > > proto method foo(Int() $x) {*} > multi method foo($x) { > > $x.WHAT.say; #-> Str > > } > } > > A.foo('1'); > $x gets coerced but the coerced value doesn't travel downstream. >
I wouldn't expect it, nor defaults, to do so; the multis are still subs with their own signatures. Further, we rely on the ability to not have to really call an onlystar proto at all for optimization, and since all operators are multi-dispatch, that's important. Arguably, the use of certain features in an onlystar proto could add a note to the "potential difficulties", since it's very likely a thinko. /jnthn
Subject: Re: [perl #126417] [BUG] proto signature default values don't work (NYI?)
Date: Wed, 28 Oct 2015 02:07:34 +1100
To: "Lloyd Fournier (via RT)" <perl6-bugs-followup [...] perl.org>
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Download (untitled) / with headers
text/plain 1.7k
Welcome back jnthn :)

That makes sense. I thought that proto was a magic way to set defaults for all parameters for all the sigs in a multi dispatch ie don't repeat yourself. Mostly because:

 perl6 -e 'proto sub test(Str $x){*}; multi sub test($x) { $x.say }; test(Int);'

fails. But it looks like proto is only there to check args, it can't change the arguments of the original dispatch. 

I guess the proper way to do what I wanted would be to simply to set parameter defaults/coercions generously in one multi and then re-dispatch.

Agree re helping out others with the same misunderstanding with a warning. hopefully make this clear in docos soon :o)

On Wed, Oct 28, 2015 at 12:18 AM, jnthn@jnthn.net via RT <perl6-bugs-followup@perl.org> wrote:
Show quoted text
On Wed Oct 21 06:34:47 2015, lloyd.fourn@gmail.com wrote:
> lizmat++
> Fail is a good word. I didn't want to have to write throws an
> exception :o|
>
> I don't totally get the concept of { * } so I won't comment whether
> defaults working makes sense or not but it's interesting to note that
> coercions don't work in a similar fashion:
>
> class A {
>
> proto method foo(Int() $x) {*}
> multi method foo($x) {
>
> $x.WHAT.say; #-> Str
>
> }
> }
>
> A.foo('1');
> $x gets coerced but the coerced value doesn't travel downstream.
>
I wouldn't expect it, nor defaults, to do so; the multis are still subs with their own signatures. Further, we rely on the ability to not have to really call an onlystar proto at all for optimization, and since all operators are multi-dispatch, that's important. Arguably, the use of certain features in an onlystar proto could add a note to the "potential difficulties", since it's very likely a thinko.

/jnthn




This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org