Eachunion member has an associated constructor and accessor.
The symbol-name of the name of the constructor corresponding to a particular member is the concatenation of the name of the union constructor to the scoping separator to the name of the member. The home package of the name of the constructor corresponding to a particular member is the home package of the name of the union constructor. A constructor corresponding to a member takes a single argument, the value of the union. The discriminator is set to the value of the first case label corresponding to that member.
It is an error if a member reader is invoked on a union whose discriminator value is not legal for that member. The member writer sets the discriminator value to the first case label corresponding to that member.
The default member is treated as if it were a member nameddefault whose case labels include all legal case labels that are not case labels of other members in the union.
For example, in IDL:
module example {
enum enum_type {first,second,third,fourth,fifth};
union union_type switch (enum_type) {
case first: long win;
case second: short place;
case third:
case fourth: octet show;
default: boolean other;
};
};
In generated Lisp:
(defpackage :example) (defstruct (example:union_type ...))
And in use:
(setq union
(example:union_type
:union-discriminator :first
:union-value -100000))
(op:union-value union)
> -100000
(op:union-discriminator union)
> :FIRST
(setq same-union (example:union_type/win -100000))
(op:union-discriminator same-union)
> :FIRST
(setf (op:show same-union) 3)
> 3
(op:union-discriminator same-union)
> :THIRD
(op:show same-union)
> 3
(setf (op:default same-union) nil)
> nil
(op:union-discriminator same-union)
> :FIFTH