Adriaan van Os wrote:
Frank Heckenbach wrote:
BTW, apart from the syntax, the topic reminds me of another thing. For some time, I've had the idea of extensible enum types (unlike with records, there's currently no alternative in GPC, except using integer constants, of course). Even if you have no "forks", that would be useful across modules (where you can't always declare the largest type first, and the other ones as subranges).
Something like this ?
TYPE Enum0 = (e0, e1, e2); Enum1 = (( Enum0) e3, e4)
Perhaps, though I find the nested parentheses a little strange. At least I'd add a comma:
Enum1 = ((Enum0), e3, e4)
But actually, both seem to be very hard to parse (consider a subrange `((Enum0)) .. Foo', so the parser would have to read ahead until after the first `)' to find the difference).
BTW, the following (which might look "natural" at first sight) would not work at all:
Enum1 = (Enum0, e3, e4)
because it would be ambiguous if Enum0 is defined as an enum type in an outer scope (so it could mean an extension, or a new local enum value).
This might be easier to parse (would have to check) and perhaps look "nicer", but it wouldn't fit to the records:
Enum1 = Enum0, (e3, e4)
So, if we have two variables:
VAR V0: Enum0; V1: Emum1;
the rules of compatibilty would allow the assignment
V0:=V1
but the compiler would have to do a (optional) range check to be sure that a actual value of V1 is within the range of Enum0 ?
Exactly. Just the same as when Enum1 was declared first, and then Enum0 as a subrange of Enum1.
I like the idea.
I don't know if any dialect has something like this. If not, and we'd make up something new, maybe we could use a common (or similar) syntax with extensible records ...
Frank suggested Record (), which has the right style and serves the purpose:
T = RECORD () x, y: INTEGER END; T0 = RECORD (T) z: REAL END; T1 = RECORD (T) w: LONGREAL END;
The more I think about it, the more it seems logical to me (though empty parentheses in general look strange to me) ...
Frank