-
-
Save anonymous/d548488b1c3ad9abde3c to your computer and use it in GitHub Desktop.
Which one do you think makes more sense?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First version, uses attributes | |
method flag-is(:$left-align, :$right-align, :$left-inverse, :$right-inverse, :$inverse, :$intra-chr) { | |
$mask = 0 +| (:left-align ?? 2 !! 0) | |
+| (:right-align ?? 1 !! 0) | |
+| (:left-inverse ?? 8 !! 0) | |
+| (:right-inverse ?? 4 !! 0) | |
+| (:right-align ?? 16 !! 0) | |
+| (:intra-chr ?? 32 !! 0); | |
return ($.flag +& $mask); | |
} | |
# Second version, uses exported bit-flags | |
constant \FL_LEFT_ALIGN is export := 2; | |
constant \FL_RIGHT_ALIGN is export := 1; | |
constant \FL_LEFT_INVERSE is export := 8; | |
constant \FL_RIGHT_INVERSE is export := 4; | |
constant \FL_INVERSE is export := 16; | |
constant \FL_INTRA_CHR is export := 32; | |
method flag-is(Int $mask) { | |
return ($.flag +& $mask); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment