Navigation Menu

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

Multiple dispatch mechanism apparently does not descend into inner signatures #1933

Closed
p6rt opened this issue Jul 13, 2010 · 11 comments
Closed

Comments

@p6rt
Copy link

p6rt commented Jul 13, 2010

Migrated from rt.perl.org#76486 (status was 'resolved')

Searchable as RT76486$

@p6rt
Copy link
Author

p6rt commented Jul 13, 2010

From @cognominal

$ cat mmd.pm6
multi sub a([]) { say "[]" }
multi sub a([$i]) { say "[$i]" }
a(); a([1]);
$ perl6 mmd.pm6
No applicable candidates found to dispatch to for 'a'. Available candidates are​:
:(Positional ())
:(Positional (Any $i))

  in main program body at line 3​:mmd.pm6
$

This makes impossible shape based pattern matching.

--
cognominal stef

@p6rt
Copy link
Author

p6rt commented Jul 13, 2010

From @moritz

Am 13.07.2010 02​:13, schrieb Stephane Payrard (via RT)​:

$ cat mmd.pm6
multi sub a([]) { say "[]" }
multi sub a([$i]) { say "[$i]" }
a(); a([1]);
$ perl6 mmd.pm6
No applicable candidates found to dispatch to for 'a'. Available candidates are​:
:(Positional ())
:(Positional (Any $i))

in main program body at line 3​:mmd.pm6
$

This is expected behaviour. Both signatures require at least one
argument, you pass in none.

If you mean to also allow no arguments at all, change your first multi to​:

multi sub a([]?) { say "[]" }

@p6rt
Copy link
Author

p6rt commented Jul 13, 2010

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

@p6rt
Copy link
Author

p6rt commented Jul 13, 2010

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

@p6rt
Copy link
Author

p6rt commented Jul 14, 2010

From @cognominal

Sorry. My example was wrong. Here another one. C<a([])> executes as
intended but
C<@​t> does not. I find that unintuitive.

cat mmd5.pm6
multi sub a(@​a) { say 1 ~ @​a.perl }
multi sub a([]) { say 2 ~ [].perl }
my @​t=(1,2);
a([]);
a(@​t)
$ perl6 mmd5.pm6
2[]
No applicable candidates found to dispatch to for 'a'. Available candidates are​:
:(@​a)
:(Positional ())

  in main program body at line 5​:mmd5.pm6
$

@p6rt
Copy link
Author

p6rt commented Jul 15, 2010

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

@p6rt
Copy link
Author

p6rt commented Oct 22, 2011

From @coke

On Wed Jul 14 15​:42​:09 2010, cognominal wrote​:

Sorry. My example was wrong. Here another one. C<a([])> executes as
intended but
C<@​t> does not. I find that unintuitive.

cat mmd5.pm6
multi sub a(@​a) { say 1 ~ @​a.perl }
multi sub a([]) { say 2 ~ [].perl }
my @​t=(1,2);
a([]);
a(@​t)
$ perl6 mmd5.pm6
2[]
No applicable candidates found to dispatch to for 'a'. Available
candidates are​:
:(@​a)
:(Positional ())

in main program body at line 5​:mmd5.pm6
$

This works now​:

$ cat foo
multi sub a(@​a) { say 1 ~ @​a.perl }
multi sub a([]) { say 2 ~ [].perl }
my @​t=(1,2);
a([]);
a(@​t)
$ ./perl6 foo
1Array.new()
1Array.new(1, 2)

Closable with tests.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Mar 2, 2012

From @moritz

Turns out that rakudo's answer is still wrong; it always calls the (@​a)
candidate, never the ([]) one​:

22​:44 < moritz> perl6​: multi sub a(@​a) { say 1 ~ @​a.perl }; multi sub
a([]) { say 2 ~ [].perl }; a []
22​:44 <+p6eval> rakudo d4dc7d​: OUTPUT«1Array.new()␤»
22​:44 <+p6eval> ..pugs b927740​: OUTPUT«*** ␤ Unexpected "[])"␤
expecting formal parameter or ")"␤ at /tmp/UwCYKvZkPH line 1, column
50␤»
22​:44 <+p6eval> ..niecza v15-2-gd19c478​: OUTPUT«2[]␤»
22​:44 < moritz> I kinda agree with niecza here
22​:45 < jnthn> Same...I'm thought we had a passing test for that case too
22​:45 < moritz> I was about to write on... and it didn't pass :/
22​:46 < jnthn> ah
22​:46 < jnthn> Something is off here.

@p6rt
Copy link
Author

p6rt commented Mar 2, 2012

From @moritz

Oh, and tests can now be found in S06-multi/unpackability.t

@p6rt
Copy link
Author

p6rt commented Mar 2, 2012

From @jnthn

On Fri Oct 21 19​:24​:38 2011, coke wrote​:

On Wed Jul 14 15​:42​:09 2010, cognominal wrote​:

Sorry. My example was wrong. Here another one. C<a([])> executes as
intended but
C<@​t> does not. I find that unintuitive.

cat mmd5.pm6
multi sub a(@​a) { say 1 ~ @​a.perl }
multi sub a([]) { say 2 ~ [].perl }
my @​t=(1,2);
a([]);
a(@​t)
$ perl6 mmd5.pm6
2[]
No applicable candidates found to dispatch to for 'a'. Available
candidates are​:
:(@​a)
:(Positional ())

in main program body at line 5​:mmd5.pm6
$

This works now​:

$ cat foo
multi sub a(@​a) { say 1 ~ @​a.perl }
multi sub a([]) { say 2 ~ [].perl }
my @​t=(1,2);
a([]);
a(@​t)
$ ./perl6 foo
1Array.new()
1Array.new(1, 2)

Closable with tests.

This wasn't the right answer, but we get it now​:

2[]
1Array.new(1, 2)

And moritz++ wrote tests, with I've now untodo'd, so resolving.

Merci,

/jnthn

@p6rt
Copy link
Author

p6rt commented Mar 2, 2012

@jnthn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant