Next: , Previous: , Up: More About Types in Python   [Contents][Index]


5.2.3 Member Types

The member type specifier can be used to represent “symbolic” values, analogous to the enumerated types of Pascal. For example, the second value of find-symbol has this type:

(member :internal :external :inherited nil)

Member types are very useful for expressing consistency constraints on data structures, for example:

(defstruct ice-cream
  (flavor :vanilla :type (member :vanilla :chocolate :strawberry)))

Member types are also useful in type inference, as the number of members can sometimes be pared down to one, in which case the value is a known constant.