hubert@lifia.UUCP (Hubert GARAVEL) (04/14/86)
(I don't know much about MODULA-2, but I think what I say can be relevant for M2 as well as it is for PASCAL) Did anybody notice that PASCAL use true overloading for "record" data structures? Consider two "record" types T1 and T2, each of them having a field named F. When the compiler sees S.F it has to decide whether S is of type T1 or T2 to generate valuable code. ".F" is a unary post-fixed overloaded operator, because its semantics depends upon the type of its operand. -- It is necessary for I/O procedures ("write", "read") to have a flexible format: overloading is the least a language should provide. But, especially for outputs on text-files, a variable number of parameters is suited. On the contrary, variable number of parameters raises very difficult problems: - how handle the effective arguments in the procedure body ? - how conduct compile-time type-checking ? - how carry data flow analysis ? ADA's definition sacrifies ease-of-use to these implementation constraints On the opposite, PASCAL allows "magic" I/O procedures which are more priviled- ged than user-defined procedures. I think there is an (elegant) way to conciliate these two aims: Suppose defined "&" a concatenation operator which is overloaded as follows: string & string -> string string & integer -> string integer & string -> string integer & integer -> string ... (eg "it's " & 3 & " o'clock" = "it's 3 o'clock") and a "write" procedure, with *ONE* argument of string type Then you can write, in the PASCAL fashion: write ("epsilon = " & EPSILON & " i = " & I) For the programmer, the "," has been replaced by a "&". Yet no extension has been made to the language: only overloading has been used (the first point of this message aimed at showing that allowing overloading is straightforward). -- Hubert GARAVEL UUCP: ... {mcvax, vmucnam} ! lifia ! hubert