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

Parrot doesn't distinguish hash access from array access #422

Closed
p6rt opened this issue Nov 21, 2008 · 10 comments
Closed

Parrot doesn't distinguish hash access from array access #422

p6rt opened this issue Nov 21, 2008 · 10 comments

Comments

@p6rt
Copy link

p6rt commented Nov 21, 2008

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

Searchable as RT60732$

@p6rt
Copy link
Author

p6rt commented Nov 21, 2008

From @moritz

From #perl6 today​:

19​:33 < moritz_> rakudo​: my $x = [ 42 ]; say $x<0>
19​:33 < p6eval> rakudo 32984​: OUTPUT[42␤]

I don't think that should be allowed.

Cheers,
Moritz

--
Moritz Lenz
http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/

@p6rt
Copy link
Author

p6rt commented Nov 22, 2008

From @particle

On Fri, Nov 21, 2008 at 10​:43, via RT Moritz Lenz
<perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Moritz Lenz
# Please include the string​: [perl #​60732]
# in the subject line of all future correspondence about this issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=60732 >

From #perl6 today​:

19​:33 < moritz_> rakudo​: my $x = [ 42 ]; say $x<0>
19​:33 < p6eval> rakudo 32984​: OUTPUT[42␤]

I don't think that should be allowed.

the real test is​:

(8​:52​:47 PM) [particle]1​: rakudo​: my $x = [42]; say $x<0_but_true>;
(8​:52​:49 PM) p6eval​: rakudo 32998​: OUTPUT[42␤]
(8​:53​:38 PM) [particle]1​: rakudo​: my $x = [42]; say $x<true_but_0>;
(8​:53​:40 PM) p6eval​: rakudo 32998​: OUTPUT[42␤]
(8​:53​:50 PM) [particle]1​: rakudo​: my $x = [42]; say $x<XXX>;
(8​:53​:52 PM) p6eval​: rakudo 32998​: OUTPUT[42␤]
(8​:54​:37 PM) [particle]1​: rakudo​: my $x = ['a', 42]; say $x<XXX>;
(8​:54​:39 PM) p6eval​: rakudo 32998​: OUTPUT[a␤]
(8​:58​:41 PM) [particle]1​: rakudo​: my $x = ['a', 42]; say $x<1.4>;
(8​:58​:44 PM) p6eval​: rakudo 32998​: OUTPUT[42␤]
(8​:58​:48 PM) [particle]1​: rakudo​: my $x = ['a', 42]; say $x<0.4>;
(8​:58​:50 PM) p6eval​: rakudo 32998​: OUTPUT[a␤]

so, the index is coerced to an integer. is that really wrong?
~jerry

@p6rt
Copy link
Author

p6rt commented Nov 22, 2008

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

@p6rt
Copy link
Author

p6rt commented Nov 24, 2008

From @moritz

jerry gay wrote​:

On Fri, Nov 21, 2008 at 10​:43, via RT Moritz Lenz
<perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Moritz Lenz
# Please include the string​: [perl #​60732]
# in the subject line of all future correspondence about this issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=60732 >

From #perl6 today​:

19​:33 < moritz_> rakudo​: my $x = [ 42 ]; say $x<0>
19​:33 < p6eval> rakudo 32984​: OUTPUT[42␤]

I don't think that should be allowed.

the real test is​:

(8​:52​:47 PM) [particle]1​: rakudo​: my $x = [42]; say $x<0_but_true>;
(8​:52​:49 PM) p6eval​: rakudo 32998​: OUTPUT[42␤]
(8​:53​:38 PM) [particle]1​: rakudo​: my $x = [42]; say $x<true_but_0>;
(8​:53​:40 PM) p6eval​: rakudo 32998​: OUTPUT[42␤]
(8​:53​:50 PM) [particle]1​: rakudo​: my $x = [42]; say $x<XXX>;
(8​:53​:52 PM) p6eval​: rakudo 32998​: OUTPUT[42␤]
(8​:54​:37 PM) [particle]1​: rakudo​: my $x = ['a', 42]; say $x<XXX>;
(8​:54​:39 PM) p6eval​: rakudo 32998​: OUTPUT[a␤]
(8​:58​:41 PM) [particle]1​: rakudo​: my $x = ['a', 42]; say $x<1.4>;
(8​:58​:44 PM) p6eval​: rakudo 32998​: OUTPUT[42␤]
(8​:58​:48 PM) [particle]1​: rakudo​: my $x = ['a', 42]; say $x<0.4>;
(8​:58​:50 PM) p6eval​: rakudo 32998​: OUTPUT[a␤]

so, the index is coerced to an integer. is that really wrong?
~jerry

IMHO yes, because Perl explicitly distinguishes between arrays and
hashes (and it's one of the things we never regretted, I think ;-). Any
intermixing between the two would only lead to confusion, especially if
somebody writes a class whose objects are both hashe and array.

But that's just my two cents, CC'ing p6l for clarification.

Moritz

@p6rt
Copy link
Author

p6rt commented Nov 24, 2008

From @pmichaud

On Fri, Nov 21, 2008 at 10​:43​:15AM -0800, Moritz Lenz wrote​:

From #perl6 today​:

19​:33 < moritz_> rakudo​: my $x = [ 42 ]; say $x<0>
19​:33 < p6eval> rakudo 32984​: OUTPUT[42␤]

I don't think that should be allowed.

It's allowed at least for Match objects -- from S05​:

  # The numbered captures may be treated as named,
  so $&lt;0 1 2&gt; is equivalent to $/[0,1,2]. This allows
  you to write slices of intermixed named and numbered captures.

I agree that it's probably not allowed in the general case of
indexing a List or Array, though. We will probably fix this when
we implement postcircumfix​:<{ }> and postcircumfix​:<[ ]> as part
of handling list and hash slices.

Pm

@p6rt
Copy link
Author

p6rt commented Nov 29, 2008

From @masak

<masak> rakudo​: grammar G { token TOP { ^ <foo>+ $ }; token foo { '​:'
<bar>? }; token bar { \w } }; "​:a​:b" ~~ G; say ~$/<foo><bar> # is
this a bug? shouldn't ~$/<foo><bar> be just 'a' ?
<p6eval> rakudo 33354​: OUTPUT[​:a␤]
<pmichaud> rakudo​: grammar G { token TOP { ^ <foo>+ $ }; token foo {
'​:' <bar>? }; token bar { \w } }; my $m = G​::TOP('​:a​:b'); say
$m<foo><bar>;
<p6eval> rakudo 33354​: OUTPUT[​:a␤]
<pmichaud> rakudo​: grammar G { token TOP { ^ <foo>+ $ }; token foo {
'​:' <bar>? }; token bar { \w } }; my $m = G​::TOP('​:a​:b'); say
$m<foo>;
<p6eval> rakudo 33354​: OUTPUT[​:a​:b␤]
<pmichaud> rakudo​: grammar G { token TOP { ^ <foo>+ $ }; token foo {
'​:' <bar>? }; token bar { \w } }; my $m = G​::TOP('​:a​:b'); say
$m<foo><bar>[0];
<p6eval> rakudo 33354​: OUTPUT[Use of uninitialized value␤␤]
<pmichaud> rakudo​: grammar G { token TOP { ^ <foo>+ $ }; token foo {
'​:' <bar>? }; token bar { \w } }; my $m = G​::TOP('​:a​:b'); say
$m<foo>[0]<bar>[0];
<p6eval> rakudo 33354​: OUTPUT[a␤]
<pmichaud> masak​: the problem is that Parrot doesn't distinguish hash
access from array access
<pmichaud> so $/&lt;foo&gt;&lt;bar&gt; is actually the same as $/<foo>[0]
<pmichaud> because $/<foo> is an array.
<masak> pmichaud​: so, is it a bug or not?
<pmichaud> yes, but I'm not sure where yet.
<masak> pmichaud​: I'll report it, then.

@p6rt
Copy link
Author

p6rt commented Dec 1, 2008

From @pmichaud

Just a note that I expect we will fix this when we implement
slicing and the postcircumfix​: methods.

Pm

@p6rt
Copy link
Author

p6rt commented Dec 20, 2008

From @pmichaud

Now fixed in r34137, thanks!

Pm

1 similar comment
@p6rt
Copy link
Author

p6rt commented Dec 20, 2008

From @pmichaud

Now fixed in r34137, thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Dec 20, 2008

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

@p6rt p6rt closed this as completed Dec 20, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant