Skip to content
Permalink
Browse files

Fix roundtrippability of QuantHashes

- Set(|Hash) perlifies as Foo.new(...)
- Bag(|Hash)|Mix(|Hash) perlifies as (...).Baggy (as coercer)
- No longer specical case frequency/weight of 1

This seems inconsistent, but there is a reason for this.

When a Setty is perlified, the objects of the Set need to be represented
*without* any further interpretation.  The fact that they occur in the .perl
representation, indicates that that object needs to be put in the Setty
*as is* when EVALled.

This is different for Baggy's, as Baggy's have a frequency / weight attached
to the object.  That frequence / weight is expressed as a Pair with .perl.
The weight / frequency information of Pairs is *only* interpreted when
*coercing* to a Baggy.  Before, when the frequency / weight of an object
in a Baggy was 1, it would not show this in the perlification.

This was wrong, as it introduced ambiguity between a Pair with weight 1,
and an object with the same value as the key of such a Pair.  So:

    (a => 42) => 1

would perlify the same as:

    a => 42

This is now fixed.
  • Loading branch information...
lizmat committed Jun 30, 2018
1 parent 3cbf25e commit ddf496c72b2d90b9b02c7729d2d5806a71791a85
Showing with 10 additions and 11 deletions.
  1. +6 −4 src/core/Baggy.pm6
  2. +4 −7 src/core/Setty.pm6
@@ -332,10 +332,12 @@ my role Baggy does QuantHash {
'(',
nqp::join(',',
Rakudo::QuantHash.RAW-VALUES-MAP(self, {
nqp::if(
(my $value := nqp::getattr($_,Pair,'$!value')) == 1,
nqp::getattr($_,Pair,'$!key').perl,
"{nqp::getattr($_,Pair,'$!key').perl}=>$value"
nqp::concat(
nqp::concat(
nqp::getattr($_,Pair,'$!key').perl,
'=>'
),
nqp::getattr($_,Pair,'$!value').perl
)
})
)
@@ -162,14 +162,11 @@ my role Setty does QuantHash {
nqp::eqaddr(self,set()),
'set()',
nqp::concat(
'(',
nqp::concat(
nqp::join(",",Rakudo::QuantHash.RAW-VALUES-MAP(self, *.perl)),
nqp::concat(
').',
self.^name
)
)
nqp::concat(self.^name,'.new('),
nqp::join(",",Rakudo::QuantHash.RAW-VALUES-MAP(self, *.perl))
),
')'
)
)
}

0 comments on commit ddf496c

Please sign in to comment.
You can’t perform that action at this time.