3 ms·
Crystal has a Flag attribute for enums (Flag enums): http://crystal-lang.org/docs/syntax_and_semantics/enum.html http://crystal-lang.org/docs/syntax_and_semant
by haar 10y ago
Crystal has a Flag attribute for enums (Flag enums):
http://crystal-lang.org/docs/syntax_and_semantics/enum.html http://crystal-lang.org/docs/syntax_and_semantics/enum.html
- dom96 10y agoNim supports sets which IMO is a much better solution: http://nim-lang.org/docs/manual.html#types-set-type http://nim-lang.org/docs/manual.html#types-set-type
- PeCaN 10y agoTaken from Pascal and other Wirthian languages. Nim actually looks vaguely Wirthish in some areas. Interesting.
- lobster_johnson 10y agoNim's author was originally a Turbo Pascal/Delphi programmer. A lot of Nim and its conventions (things like prefixing type names with T and members with F) come directly from Borland's Pascal dialect.
- Pxtl 10y agoAh, so a Set keyed with an Enum is functionally C-style "flags" then?
- dom96 10y agoPretty much. Here is an example: type EGlassRNState = enum EGlassRNState_Initial, EGlassRNState_Weakened, EGlassRNState_Shattering, EGlassRNState_Shattered, EGlassRNState_ActiveFrags proc hasGlassShattered(mState: set[EGlassRNState]): bool = EGlassRNState_Shattered in mState proc hasActiveFragments(mState: set[EGlassRNState]): bool = EGlassRNState_ActiveFrags in mState assert hasActiveFragments({EGlassRNState_Shattered, EGlassRNState_ActiveFrags})