Daniel Ruoso pointed out:
> Using bitsets in Perl 6 is just as easy as using in Perl 5 -- which
> happens to be the same as using in C, but it's not C...
>
> constant PERM_WRITE = 0b0001;
> constant PERM_READ = 0b0010;
> constant PERM_EXEC = 0b0100;
> constant PERM_NAMES = { PERM_WRITE => 'Write',
> PERM_READ => 'Read',
> PERM_EXEC => 'Exec' };
> subset Perm of Int where * < 8;
Sure. This certainly works, but the technique requires the developer to
hard-code each name twice and to hard-code the constant 8 as well.
This seems unfortunately brittle from a maintainability point of view.
I know hardware engineers aren't supposed to care about maintainability,
but I'd like us to make it easier for them to do the right thing than not. ;-)
> The thing that bugs me is that sets have way more uses then bitsets, and
> we might be overspecializing sets to support that semantics.
Yes. I have the same concern.
> If there's a strong case for bitsets, maybe it's worth having a
> specialized declarator.
Or maybe it doesn't need to be core syntax at all and I just need to create
a module that implements my original dream syntax/semantics; namely
a macro implementing a C<bitset> type declarator that allows:
use Type::Bitset;
bitset Perms <Read Write Exec Fold Spindle Mutilate>;
# Declares enumerated constants with successive powers-of-two values
# Also declares: subset Perms of Int where 0 .. [+|] @constant_values;
# Hence allows:
my Perms $perms = Read +| Write +| Mutilate; # Okay
my Perms $bad_perms = Read +| Write +| 42; # Error
Aw heck, now that I've specified it, the implementation is just a SMOP.
Forget I asked. I'll just write it myself! ;-)
Damian