Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum (cont) space returns false even if it contains a space #2604

Closed
Kaiepi opened this issue Jan 12, 2019 · 5 comments
Closed

Enum (cont) space returns false even if it contains a space #2604

Kaiepi opened this issue Jan 12, 2019 · 5 comments

Comments

@Kaiepi
Copy link
Contributor

Kaiepi commented Jan 12, 2019

The Problem

See title.

Expected Behavior

enum ∋ ' ' should return True.

Actual Behavior

It returns False.

Steps to Reproduce

enum Foo «' '»;
say Foo.enums ∋ ' ';

Environment

  • Operating system:
    OpenBSD bastille.kennel.qt 6.4 GENERIC.MP#364 amd64
  • Compiler version (perl6 -v):
    This is Rakudo version 2018.12-158-gf39be10ce built on MoarVM version 2018.12-13-g473324ee3
    implementing Perl 6.d.
@lizmat
Copy link
Contributor

lizmat commented Jan 12, 2019

This problem is not just for homemade enums or special enums like with a space. It's for all enums with a False value:

dd Endian.enums; # Map.new((:BigEndian(2),:LittleEndian(1),:NativeEndian(0)))
say Endian.enums (cont) NativeEndian;  # False

enum Foo (a => "foo", b => "");
dd Foo.enums;  # Map.new((:a("foo"),:b("")))
say Foo.enums (cont) "a";  # True
say Foo.enums (cont) "b";  # False

@lizmat
Copy link
Contributor

lizmat commented Jan 12, 2019

Actually, this has nothing to do with enums:

my %h = a => 0, b => 1;
say "a" (elem) %h;   # False
say "b" (elem) %h;   # True

@lizmat
Copy link
Contributor

lizmat commented Jan 12, 2019

And from there: this is actually not a bug, but a result of Set semantics: elem and friends apply them to their parameters. So if you say:

say Endian.enums (cont) NativeEndian;  # False

You are actually saying:

say Endian.enums.Set (cont) NativeEndian;  # False

Which makes sense if you see:

dd Endian.enums.Set; # Set.new("LittleEndian","BigEndian")

So maybe we need to document this gotcha.

@lizmat
Copy link
Contributor

lizmat commented Jan 13, 2019

An alternate way to check if something is in an enum, is to use :exists:

enum Foo <a b c>;
say Foo.enums<a>;          # 0
say Foo.enums<a>:exists;   # True

@lizmat
Copy link
Contributor

lizmat commented Jan 13, 2019

Trap documented with Raku/doc@ca3067e5e7 , closing now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants