On Wed Jan 14 03:41:13 2009, richardh wrote:
> After playing with enums, I got the following:
> 
> perl6
>  > enum day <<:Sun(1) Mon Tue Wed Thr Fri Sat>>; my $x does day; 
> $x.pick; say $x
> Use of uninitialized value
.pick is implemented on enums now. Your example works, but note you
probably meant say $x.pick - .pick is not in place.

>  > enum day <<:Sun(1) Mon Tue Wed Thr Fri Sat>>; my $x does day; $x = 
> Tue; say $x
> 2
> # If Sun -> 1, then Tue should be 3
> 
Rakudo doesn't parse pairs in there yet, so you need to use:

enum day (:Sun(1), 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat');

For now, which does work. (Sun is 1, Mon is 2, etc)

> perl6
>  > enum roman [ i => 1, x => 10, v => 5]; my $x does roman = v; say $x
> too few arguments passed (0) - 1 params expected

Note it should be (...) now not [...]. But now:

enum roman ( i => 1, x => 10, v => 5 ); my $x does roman = v; say $x

Gives 5.

>  > enum roman [ i => 1, x => 10, v => 5]; my $x does roman; $x = v; say $x
> too few arguments passed (0) - 1 params expected

This gives 5 too now.

>  > enum roman [ i => 1, x => 10, v => 5]; my $x does roman; $x='v'; say $x
> v
> 
You're just assigning a string to $x here, which has nothing to do with
the enum value. So Rakudo is right here.

> assigning v to $x should yield 10 as a value
> 
Note v => 5, not 10. :-)

> Summary, it seems that enum works so long as the underlying value is a 
> list starting at 0
>  
Well, there were other issues too, which I think are mostly fixed up
now. But seems that in current Rakudo with enums improved today (aside
from the separate non-enum-related issue of the quote parsing) things
are working pretty much as you'd expect.

Thanks,

Jonathan

Reply via email to