Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto signature default values don't work (NYI?) #4665

Open
p6rt opened this issue Oct 21, 2015 · 6 comments
Open

proto signature default values don't work (NYI?) #4665

p6rt opened this issue Oct 21, 2015 · 6 comments
Labels
Bug

Comments

@p6rt
Copy link

@p6rt p6rt commented Oct 21, 2015

Migrated from rt.perl.org#126417 (status was 'open')

Searchable as RT126417$

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 21, 2015

From @LLFourn

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.

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 21, 2015

From @lizmat

¢

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-archive.perl.org/perl6/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

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 21, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 21, 2015

From @LLFourn

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​:

¢

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-archive.perl.org/perl6/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

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 27, 2015

From @jnthn

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

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 27, 2015

From @LLFourn

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​:

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

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.