You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
my%pairings=%( A =>"T",
T =>"A",
C =>"G",
G =>"C" );
constant length =3;
enumChain ( A =>"T", G =>"C", T =>"A");
for^length {
my$base= Chain.pick;
say"{$base.key} with {$base.value} and {$base.succ.pair}";
}
enumChain2 ();
for <A C G T>.roll( length ) ->$letter {
Chain2.HOW.add_enum_value( Chain2, $letter=>%pairings{$letter} );
}
for^length {
my$base= Chain2.pick;
say"{$base.key} with {$base.value}";
}
However, the behavior of the first, "naturally" created enum is different from the second. The first returns Enumeration objects, while the second returns just Pairs. Enumeration objects do have the prev and succ methods, while other objects need not have that.
Expected Behavior
add_enum_value uses anything with a key and value. When an enum is built as a type, Pairs are converted to Enumerations (I assume). When you use add_enum_value, they are admitted without conversion.
The expected behavior would make them behave consistently, with Pairs converted to Enumeration or with that role mixed in.
Actual Behavior
Building enums step by step is going to behave differently from the declaration.
Steps to Reproduce
Run above program with any Perl 6
The text was updated successfully, but these errors were encountered:
JJ
added a commit
to Raku/doc
that referenced
this issue
Aug 1, 2018
my%pairings=%( A =>"T",
T =>"A",
C =>"G",
G =>"C" );
constant length =3;
enumChain ( A =>"T", G =>"C", T =>"A");
for^length {
my$base= Chain.pick;
say"{$base.key} with {$base.value} and {$base.succ.pair}";
}
enumChain2 ();
for <A C G T>.roll( length ) ->$letter {
Chain2.HOW.add_enum_value( Chain2, Chain2.bless:key =>$letter, value =>%pairings{$letter} );
}
Chain2.^compose_values;
for^length {
my$base= Chain2.pick;
say"{$base.key} with {$base.value} and {$base.succ.pair}";
}
Looks that the enum values must be a instance of that enum type.
enum values have to be an instance of Enumeration, not enum, which is a set of Enumerations. But the problem is that they don't become that automatically, only when you use ^compose_values. That means that they are somehow turned into Enumerations when composed, but I don't see why that couldn't happen when they are being added in add_enum_value.
The Problem
enumscan be created using theenumHOWprotocol:However, the behavior of the first, "naturally" created enum is different from the second. The first returns
Enumerationobjects, while the second returns just Pairs.Enumerationobjects do have theprevandsuccmethods, while other objects need not have that.Expected Behavior
add_enum_valueuses anything with a key and value. When anenumis built as a type, Pairs are converted to Enumerations (I assume). When you use add_enum_value, they are admitted without conversion.The expected behavior would make them behave consistently, with Pairs converted to
Enumerationor with that role mixed in.Actual Behavior
Building
enums step by step is going to behave differently from the declaration.Steps to Reproduce
Run above program with any Perl 6
The text was updated successfully, but these errors were encountered: