Proposal: Enum types as valid With-statement parameters
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Thu Jul 20 22:42:47 PDT 2006
I recently found myself writing the following code:
# struct Var {
#
# // ... other stuff ...
#
# bool truth () {
# switch (type) {
# case VarType.Clear :
# case VarType.Error : return false ;
# case VarType.Object : return o !is null ;
# case VarType.Int : return i != 0_L ;
# case VarType.Float : return f != 0.0_L ;
# case VarType.String : return s.length != 0 ;
# case VarType.Symbol : return validSymbol() ;
# case VarType.Bool : return b ;
# case VarType.List : return l.length != 0 ;
# case VarType.Map : return m.keys.length != 0 ;
# case VarType.Frob : return true ;
# }
# }
#
# // ... other stuff ...
#
# }
It would have been nice to be able to write this as:
# struct Var {
#
# // ... other stuff ...
#
# bool truth () {
# with (VarType) switch (type) {
# case Clear :
# case Error : return false ;
# case Object : return o !is null ;
# case Int : return i != 0_L ;
# case Float : return f != 0.0_L ;
# case String : return s.length != 0 ;
# case Symbol : return validSymbol() ;
# case Bool : return b ;
# case List : return l.length != 0 ;
# case Map : return m.keys.length != 0 ;
# case Frob : return true ;
# }
# }
#
# // ... other stuff ...
#
# }
Walter: how difficult would it be to allow named Enum types as valid With-statement
parameters? When named Enums are used in tandem with constructs such as Switch, this
could save quite a lot of typing, and is still perfectly clear when reading code.
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list