Is it possible to define two enums in raku that share the same identifiers?
For example, if I have the following code:
#!/usr/bin/raku
use v6;
enum Color <Red Blue>;
enum TrafficLight <Red Green>;
sub MAIN(
Color:D :c(:$color)!, #= the color
TrafficLight:D :t(:$traffic-light)!, #= the traffic-light
) {
say "Selected $color, Selected $traffic-light"
}
you can see that here, the identifer Red is part of the enum color and the enum TrafficLight.
But when I execute this script, I get the Redeclaration-exception:
$ ./test.p6
Potential difficulties:
Redeclaration of symbol 'Red'
at /home/martin/mnt/release-notes/./scripts/test.p6:5
------> enum TrafficLight <Red Green>⏏;
Usage:
./scripts/test.p6 -c|--color=<Color> (Blue Red) -t|--traffic-light=<TrafficLight> (Green Red)
-c|--color=<Color> (Blue Red) the color
-t|--traffic-light=<TrafficLight> (Green Red) the traffic-light
Interestingly, when I execute this script with the parameters -c=Blue and -t=Red, the output is that that I would expect:
$ ./test.p6 -c=Blue -t=Red
Potential difficulties:
Redeclaration of symbol 'Red'
at /home/martin/mnt/release-notes/./scripts/test.p6:5
------> enum TrafficLight <Red Green>⏏;
Selected Blue, Selected Red
But when I exeucte this script with the parameters -c=Red and -t=Green, it doesn't work at all and error-code 2 is returned (showing the help-message).
My questions are now:
- Is it possible to define two same Enum-Identifiers that have the same name (but different types). Maybe it is possible to define an enum similar to class-enums in C++ with a
namespacesurrounding them? - Is it possible to catch this exception somehow?
Thanks