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

What should be returned by the .keys method for Match invocants? #2054

Closed
p6rt opened this issue Aug 10, 2010 · 8 comments
Closed

What should be returned by the .keys method for Match invocants? #2054

p6rt opened this issue Aug 10, 2010 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 10, 2010

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

Searchable as RT77146$

@p6rt
Copy link
Author

p6rt commented Jan 20, 2009

From eric.hodges@gmail.com

use v6;

rule test {test};

"test" ~~ /<test>/;
say '$/.keys => ', $/.keys.perl;
say '%($/).keys =&gt; ', %($/).keys.perl;

# outputs
# $/.keys => []
# %($/).keys => ["test"]

Same could be said for .values and .kv

It would be very DWIM for it to act like a hash in these cases by default.

@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

From @coke

On Tue Jan 20 12​:58​:20 2009, eric256 wrote​:

use v6;

rule test {test};

"test" ~~ /<test>/;
say '$/.keys => ', $/.keys.perl;
say '%($/).keys =&gt; ', %($/).keys.perl;

# outputs
# $/.keys => []
# %($/).keys => ["test"]

Same could be said for .values and .kv

It would be very DWIM for it to act like a hash in these cases by default.

Here's a slightly updated version​:

$ more foo.p6
use v6;

our rule test {test};

"test" ~~ /(<&test>)/;
say '$/.keys => ', $/.keys.perl;
say '%($/).keys =&gt; ', %($/).keys.perl;

$ ./perl6 foo.p6
$/.keys => (0)
%($/).keys => ()

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

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

@p6rt
Copy link
Author

p6rt commented Aug 10, 2010

From @cognominal

I edited my garbled sentences.

[15​:28​:22] <cognominal> I know that a match is both an array and a
hash and that both containers have a .keys method. But I would expect
.keys for a Match to return a list of the named reductions
[15​:28​:37] <cognominal> rakudo​: grammar A { token TOP { <a> }; token
a { a } }; class A​::A { method TOP($/) { say $&lt;a>.keys }} ;
A.parse( 'a', :actions(A​::A))
[15​:28​:42] <p6eval> rakudo 4bd478​: OUTPUT«␤»
[15​:29​:09] <moritz_> the spec isn't clear on that point
[15​:31​:36] <cognominal> I think it can be useful on actions for a
rule that is a mere alternation list. method alternation($/) {
  make $/."{($/.keys)[0]}".ast } # if I got that right
[15​:32​:00] <masak> fwiw, I'd also expect the subrule names from .keys
[15​:32​:31] <moritz_> cognominal​: are you sure you don't want .caps for that?
[15​:33​:06] * masak .oO( .shower-caps )
[15​:33​:24] <moritz_> that said, I could very well live with
Match.keys returning (Match.list.keys, Match.hash.keys)
[15​:33​:41] <moritz_> and likewise .values and .kv

--
cognominal stef

@p6rt
Copy link
Author

p6rt commented May 11, 2013

From @FROGGS

TimToady​: a Match object should return both array and hash keys in the
absence of further guidance as to which is wanted (implementations tend
to store the numeric keys in the hash in any case for convenience)

@p6rt
Copy link
Author

p6rt commented May 11, 2013

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

@p6rt
Copy link
Author

p6rt commented Feb 9, 2015

From @Mouq

This appears to have been a resolved issue for some time, both in spec and in implementation. I've added a test in Roast commit​:

commit bb73feaaa6bdd3d0a89a701552c7e4ca5e41a2f4
Author​: Mouq <alexmoquin@​gmail.com>
Date​: Mon Feb 9 00​:59​:13 2015 -0500

  Add test for RT #​77146

Marking this ticket as resolved :)

On Sat May 11 01​:13​:10 2013, FROGGS.de wrote​:

TimToady​: a Match object should return both array and hash keys in the
absence of further guidance as to which is wanted (implementations tend
to store the numeric keys in the hash in any case for convenience)

@p6rt
Copy link
Author

p6rt commented Feb 9, 2015

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

@p6rt p6rt closed this as completed Feb 9, 2015
@p6rt p6rt added the spec 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