Can I suggest a new method to be declared with enums, viz. .face

enum day <<Sun Mon Tue Wed Thur Fri Sat>>;
my $today does day;
$today = prompt "Type in a day of the week ";

#later
say $today ;  #  prints 3
say $today.face;  #prints  Wed

Whilst having an enum being a list of values is useful, not being able to restore the name can be frustrating.

Carl Mäsak wrote:
Richard (>):
S12 defines enums and rakudo impliments them, so
perl6
enum wkend <<Sat Sun>>; my $x = Sun; say $x
1

But suppose I want to get the "face value" of $x, viz., 'Sun'?

How do I get it?

say $x.key doesnt work.

Far as I know, the answer to your question is unspecced.

(Yes, that sucks. I've also wanted the name of an enum value
sometimes, but so far I've had to work around it in various ways.)

// Carl

Reply via email to