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

Array subsignatures confused by pair elements #6077

Closed
p6rt opened this issue Feb 15, 2017 · 6 comments
Closed

Array subsignatures confused by pair elements #6077

p6rt opened this issue Feb 15, 2017 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Feb 15, 2017

Migrated from rt.perl.org#130787 (status was 'rejected')

Searchable as RT130787$

@p6rt
Copy link
Author

p6rt commented Feb 15, 2017

From @dwarring

Consider​:

sub s(@​ ($a, $b, $c)) {
  note [$a,$b,$c].perl;
}
s([10,20,30]);
s([10,20,v=>30]); # dies

david@​X346​:~$ perl6 -v
This is Rakudo version 2017.01-207-gb51a550 built on MoarVM version
2017.01-45-g2b0739d
implementing Perl 6.c.
david@​X346​:~$ perl6 /tmp/tst.pl
[10, 20, 30]
Too few positionals passed; expected 3 arguments but got 2 in sub-signature
  in sub s at /tmp/tst.pl line 1
  in block <unit> at /tmp/tst.pl line 5

@p6rt
Copy link
Author

p6rt commented Feb 19, 2017

From @LLFourn

I don't think this isn't a bug. This is just how signature binding works​:

my ($a,$b,$c) := [10,20,v => 30]
Too few positionals passed; expected 3 arguments but got 2
  in block <unit> at -e line 1

It makes sense to me because otherwise what would this mean?

sub s(@​($a,$b,​:$c)) { .... }

Pair elements have to become bound to named parameters in the sub-signature.

LL

On Thu, Feb 16, 2017 at 2​:43 AM David Warring <perl6-bugs-followup@​perl.org>
wrote​:

# New Ticket Created by David Warring
# Please include the string​: [perl #​130787]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130787 >

Consider​:

sub s(@​ ($a, $b, $c)) {
  note [$a,$b,$c].perl;
}
s([10,20,30]);
s([10,20,v=>30]); # dies

david@​X346​:~$ perl6 -v
This is Rakudo version 2017.01-207-gb51a550 built on MoarVM version
2017.01-45-g2b0739d
implementing Perl 6.c.
david@​X346​:~$ perl6 /tmp/tst.pl
[10, 20, 30]
Too few positionals passed; expected 3 arguments but got 2 in sub-signature
  in sub s at /tmp/tst.pl line 1
  in block <unit> at /tmp/tst.pl line 5

@p6rt
Copy link
Author

p6rt commented Feb 19, 2017

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

@p6rt
Copy link
Author

p6rt commented Feb 19, 2017

From @dwarring

On Sat, 18 Feb 2017 18​:05​:53 -0800, lloyd.fourn@​gmail.com wrote​:

I don't think this isn't a bug. This is just how signature binding works​:

my ($a,$b,$c) := [10,20,v => 30]
Too few positionals passed; expected 3 arguments but got 2
in block <unit> at -e line 1

It makes sense to me because otherwise what would this mean?

sub s(@​($a,$b,​:$c)) { .... }

Pair elements have to become bound to named parameters in the sub-signature.

LL

On Thu, Feb 16, 2017 at 2​:43 AM David Warring <perl6-bugs-followup@​perl.org>
wrote​:

# New Ticket Created by David Warring
# Please include the string​: [perl #​130787]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130787 >

Consider​:

sub s(@​ ($a, $b, $c)) {
note [$a,$b,$c].perl;
}
s([10,20,30]);
s([10,20,v=>30]); # dies

david@​X346​:~$ perl6 -v
This is Rakudo version 2017.01-207-gb51a550 built on MoarVM version
2017.01-45-g2b0739d
implementing Perl 6.c.
david@​X346​:~$ perl6 /tmp/tst.pl
[10, 20, 30]
Too few positionals passed; expected 3 arguments but got 2 in sub-signature
in sub s at /tmp/tst.pl line 1
in block <unit> at /tmp/tst.pl line 5

Agree, consensus is that it's a restriction rather than a bug. Also discussed on irc https://irclog.perlgeek.de/perl6/2017-02-15#i_14108259

  6 more elements. Show/hide.
16​:35 lucasb about ticket RT #​130787, when you need to bind a pair to a positional parameter, you can type func('a'=>1) or func((a=>1)), because plain a=>1 would be considered a named parameter, right? should this same behavior be honored inside sub-signatures? I guess it should.
16​:35 synopsebot6 Link​: https://rt-archive.perl.org/perl6//Publ​ic/Bug/Display.html?id=130787
16​:35 lucasb m​: say \('a'=>1) ~~ :($a)
16​:35 camelia rakudo-moar cf500e​: OUTPUT«True␤»
16​:35 lucasb m​: say \(['a'=>1]) ~~ :(@​a ($a))
16​:35 camelia rakudo-moar cf500e​: OUTPUT«False␤»
16​:37 lucasb m​: sub f(@​a (​:$a)) { $a }; say f(['a'=>10]) # <-- positional parameter 'a'=>10 is getting bound to named parameter :$a (?)
16​:37 camelia rakudo-moar cf500e​: OUTPUT«10␤»
16​:37 jnthn m​: say ['a'=>10].Capture.perl
16​:37 camelia rakudo-moar cf500e​: OUTPUT«\(​:a(10))␤»
16​:38 jnthn By the point the subisgnature sees it, it's just a Pair inside of an Array
16​:39 Array inherits the Capture coercion from List, which in turn promotes Pair to a named
16​:39 lucasb so, there's no way around it? :)
16​:39 jnthn Well, not without deciding to break that behavior of Array.Capture, no
16​:40 lucasb ok, thanks for the explanation, jnthn

@p6rt
Copy link
Author

p6rt commented Feb 20, 2017

From @dwarring

On Wed, 15 Feb 2017 07​:43​:01 -0800, david.warring wrote​:

Consider​:

sub s(@​ ($a, $b, $c)) {
note [$a,$b,$c].perl;
}
s([10,20,30]);
s([10,20,v=>30]); # dies

david@​X346​:~$ perl6 -v
This is Rakudo version 2017.01-207-gb51a550 built on MoarVM version
2017.01-45-g2b0739d
implementing Perl 6.c.
david@​X346​:~$ perl6 /tmp/tst.pl
[10, 20, 30]
Too few positionals passed; expected 3 arguments but got 2 in sub-signature
in sub s at /tmp/tst.pl line 1
in block <unit> at /tmp/tst.pl line 5
Fwiw, this has also caught me out in the past​:

sub yy($a, $b, $c) {}

sub xx(|c) { yy(c); }

xx(10, 20, 'v' => 30);

Too few positionals passed; expected 3 arguments but got 1
  in sub yy at /tmp/tst.pl line 1
  in sub xx at /tmp/tst.pl line 4

I'd expected the arguments to be preserved, but the final argument, being a pair, is converted to a named argument.

Just something to be aware of.

@p6rt p6rt closed this as completed Feb 20, 2017
@p6rt
Copy link
Author

p6rt commented Feb 20, 2017

@dwarring - Status changed from 'open' to 'rejected'

@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
Labels
Projects
None yet
Development

No branches or pull requests

1 participant