Stephen Leake, 2007-07-11:

> In C, this would be a union type, with a tag field that is present in
> each case of the union.
> 
> Is there something similar in Emacs CL? I looked thru the CL manual in
> Emacs info, and didn't see anything.

An object-oriented solution to this would be to have an (abstract) 
superclass `dvc-status-entry' and three subclasses 
`dvc-status-file-entry', `dvc-status-dir-entry' and 
`dvc-status-message-entry'.

(defstruct dvc-status-entry ...)
(defstruct (dvc-status-file-entry (:include dvc-status-entry)) ...)
(defstruct (dvc-status-dir-entry (:include dvc-status-entry)) ...)
(defstruct (dvc-status-message-entry (:include dvc-status-entry)) ...)

This is untested.  But something like it should work, and I think it's a 
good solution.

You could then use `etypecase' to discriminate between the different types.

A less structured, more traditional Lisp-style representation would be a 
list with the tag in its car.  Discriminate using (ecase (car ...)), and 
use destructuring-bind inside each ecase branch to access the fields (in 
xmtn, `xmtn-match' is a simple way to combine the discrimination and 
destructuring).

Christian.

_______________________________________________
Dvc-dev mailing list
[email protected]
https://mail.gna.org/listinfo/dvc-dev

Reply via email to