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

Hashes flatten lists #305

Closed
p6rt opened this issue Sep 10, 2008 · 9 comments
Closed

Hashes flatten lists #305

p6rt opened this issue Sep 10, 2008 · 9 comments

Comments

@p6rt
Copy link

p6rt commented Sep 10, 2008

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

Searchable as RT58744$

@p6rt
Copy link
Author

p6rt commented Sep 10, 2008

From @moritz

Rakudo r30946​:

08​:35 < masak> rakudo​: .perl.say for {a => ["b", "c"]}.kv # I have a fun
bug
  for you, too! :)
08​:35 < polyglotbot> OUTPUT["a"␤"b c"␤]

that should have been ["b", "c"] on the second line

08​:38 <@​moritz> rakudo​: my %a = (a => [[3], [4,5]]); say %a<a>.perl
08​:38 < polyglotbot> OUTPUT[[3, 4, 5]␤]

the should have been [[3], [4,5]]

It seems they are even stored flat​:

08​:56 <@​moritz> rakudo​: my %a = (a => [[3], [4,5]]); say %a.perl
08​:56 < polyglotbot> OUTPUT[{"a" => [3, 4, 5]}␤]

This is the bug that makes t/spec/S29-num/rounders.t so ugly (take a
look at the fudge lines to see what I mean)

Moritz

--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/

@p6rt
Copy link
Author

p6rt commented Sep 10, 2008

From @moritz

Moritz Lenz (via RT) wrote​:

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

Rakudo r30946​:

08​:35 < masak> rakudo​: .perl.say for {a => ["b", "c"]}.kv # I have a fun
bug
for you, too! :)
08​:35 < polyglotbot> OUTPUT["a"␤"b c"␤]

that should have been ["b", "c"] on the second line

08​:38 <@​moritz> rakudo​: my %a = (a => [[3], [4,5]]); say %a<a>.perl
08​:38 < polyglotbot> OUTPUT[[3, 4, 5]␤]

the should have been [[3], [4,5]]

It seems they are even stored flat​:

08​:56 <@​moritz> rakudo​: my %a = (a => [[3], [4,5]]); say %a.perl
08​:56 < polyglotbot> OUTPUT[{"a" => [3, 4, 5]}␤]

Some more insight, found out by bacek and Tene on #parrot​:

$ ./perl6 -e '(a => [[1], [2]]).perl.say'
("a" => [[1], [2]])
$ ./perl6 -e 'my %a = (a => [[1], [2]]); %a.perl.say'
{"a" => [1, 2]}
$ ./perl6 -e 'my $a = (a => [[1], [2]]); $a.perl.say'
("a" => [[1], [2]])

So it seems that the flattening happens when assigning the hash to a %h
container, but not when assigning to a $a scalar container.

Moritz

--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/

@p6rt
Copy link
Author

p6rt commented Sep 10, 2008

From @pmichaud

On Wed, Sep 10, 2008 at 12​:22​:01PM +0200, Moritz Lenz wrote​:

Moritz Lenz (via RT) wrote​:

08​:35 < masak> rakudo​: .perl.say for {a => ["b", "c"]}.kv # I have a fun
bug
for you, too! :)
08​:35 < polyglotbot> OUTPUT["a"␤"b c"␤]

that should have been ["b", "c"] on the second line

Now fixed in r30967. The problem is that the .kv method was
always stringifying the values of the output list. To illustrate​:

$ ../../parrot perl6.pbc

my %a = ('a' => 3 ); say %a.perl; say %a.kv.perl;
{"a" => 3}
["a", "3"]

Note how the hash correctly has an Int 3 but the list produced
by .kv had a Str "3".

08​:38 <@​moritz> rakudo​: my %a = (a => [[3], [4,5]]); say %a<a>.perl
08​:38 < polyglotbot> OUTPUT[[3, 4, 5]␤]
the should have been [[3], [4,5]]

This looks to me like the generic problem that Rakudo is having
with nested arrays in general, and not specific to hashes. So I'll
close this ticket for the .kv problem and we can open another one
that deals with Rakudo incorrectly constructing arrays (not having
anything to do with hashes).

Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Sep 10, 2008

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

@p6rt
Copy link
Author

p6rt commented Sep 15, 2008

From @bacek

Patrick R. Michaud wrote​:

that should have been ["b", "c"] on the second line

Now fixed in r30967. The problem is that the .kv method was
always stringifying the values of the output list. To illustrate​:

.values still stringifying values.

Trivial patch attached.

--
Bacek.

@p6rt
Copy link
Author

p6rt commented Sep 15, 2008

From @bacek

mapping.patch
diff --git a/languages/perl6/src/classes/Mapping.pir b/languages/perl6/src/classes/Mapping.pir
index d83d980..abca0b1 100644
--- a/languages/perl6/src/classes/Mapping.pir
+++ b/languages/perl6/src/classes/Mapping.pir
@@ -136,8 +136,8 @@ Returns elements of hash as array of C<Pair(key, value)>
   loop:
     unless iter goto end
     $S1 = shift iter
-    $S1 = iter[$S1]
-    push rv, $S1
+    $P1 = iter[$S1]
+    push rv, $P1
     goto loop
   end:
     .return (rv)

@p6rt
Copy link
Author

p6rt commented Nov 7, 2008

From @pmichaud

Now fixed in r32441. Here are the results​:

$ ./parrot perl6.pbc

.perl.say for {a => [<b c>]}.kv
"a"
["b", "c"]
my %a = (a => [[3], [4,5]]); say %a<a>.perl
[[3], [4, 5]]
my %a = (a => [[3], [4,5]]); say %a.perl;
{"a" => [[3], [4, 5]]}
(a => [[1], [2]]).perl.say
("a" => [[1], [2]])
my %a = (a => [[1], [2]]); %a.perl.say;
{"a" => [[1], [2]]}
my $a = (a => [[1], [2]]); $a.perl.say;
("a" => [[1], [2]])

Thanks!

Pm

1 similar comment
@p6rt
Copy link
Author

p6rt commented Nov 7, 2008

From @pmichaud

Now fixed in r32441. Here are the results​:

$ ./parrot perl6.pbc

.perl.say for {a => [<b c>]}.kv
"a"
["b", "c"]
my %a = (a => [[3], [4,5]]); say %a<a>.perl
[[3], [4, 5]]
my %a = (a => [[3], [4,5]]); say %a.perl;
{"a" => [[3], [4, 5]]}
(a => [[1], [2]]).perl.say
("a" => [[1], [2]])
my %a = (a => [[1], [2]]); %a.perl.say;
{"a" => [[1], [2]]}
my $a = (a => [[1], [2]]); $a.perl.say;
("a" => [[1], [2]])

Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Nov 7, 2008

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

@p6rt p6rt closed this as completed Nov 7, 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