Inline-Python icon indicating copy to clipboard operation
Inline-Python copied to clipboard

Unnecessary/harmful itemization of arrays as hash elements

Open moritz opened this issue 8 years ago • 2 comments

Marshalling Python objects to Perl 6 introduces an unnecessary and harmful level of itemization of arrays inside hashes/dicts, as demonstrated by this code:

use v6;
use Inline::Python;
use json:from<Python>;
.say for json::loads('["a", "b"]'); # two iterations, as expected
.say for json::loads('{ "x": ["a", "b"] }')<x>; # just one iteration

say json::loads('{ "x": ["a", "b"] }').perl; # {:x($["a", "b"])}

moritz avatar Mar 05 '17 20:03 moritz

I do have a fix, but I'm not sure what the right behavior would actually be. Both Inline::Perl5 and pure Perl 6 behave just the same:

perl6 -e 'dd EVAL q/{a => [1, 2]}/, :lang<Perl5>;' ${:a($[1, 2])} perl6 -e 'dd EVAL q/{a => [1, 2]}/;' Hash % = {:a($[1, 2])} perl6 -e 'dd {a => [1, 2]};' Hash % = {:a($[1, 2])}

niner avatar Mar 09 '17 21:03 niner

oh, good point, I hadn't realized that. You're probably right that this should stay as it is.

There's still something weird going on in the other direct, passing arrays to python function (they seem to get flattened out, due to the use *@args instead of **@args), but I guess that's a topic for another issue.

moritz avatar Mar 11 '17 11:03 moritz