
Guaranteeing Disjointness
Quote:
>Wouldn't it be cool if you could guarantee disjointness between two types
>in Dylan? For instance, the declaration:
>disjoin(<male>,<female>);
>would guarantee that if the classes <female> and <male> are disjoint in
>the current library, they stay disjoint.
>Actually, this can already be done:
>define generic anonymous (x);
>define method anonymous (x :: <male>) end;
>define sealed domain anonymous (<female>);
>Perhaps someone would like to write a macro for this...
Regretably, you can't. The macro one would like to write is (please
pardon any syntactic screwups)
define macro disjoin
{ disjoin(?t1:variable, ?t2:variable) }
=> { define generic anonymous (x);
define method anonymous (x :: ?t1) end;
define sealed domain anonymous (?t2); }
disjoin(<a>, <b>);
disjoin(<c>, <d>);
Unfortunately, the current language specification is not completely
consistent about what should happen in this situation. It *almost* says
that such a program is erroneous because the two calls to disjoin
result in two "define generic" forms for the same module variable.
Another possibility would be that each call expands into a new hygenically
renamed binding created by the "define generic", along with some hygenically
matching references to that binding. The current language specification
seems to come pretty close to saying that as well. Under such a
specification, each macro call would really create an anonymous (i.e. not
accessible from anywhere outside the code generated by the expansion of
the macro call) generic function.
There was a long discussion of this a while ago on the (now quiescent)
dylan-partners mailing list, the conclusion of which was that there were
a small number of changes that would need to be made in order to
disambiguate in favor of the first of these alternatives, and some
unknown but probably larger (possibly significantly larger) number of
changes would be required to disambiguate in favor of the second
alternative. Part of the problem with trying to do the latter is that
Moon said that when he wrote the text for the macro chapter he was
assuming the first interpretation and had not even considered the second.
Thus, there may be a number of scattered subtle or not so subtle changes
needed to make everything consistent with the second interpretation.
Which is really too bad, if you ask me.