Prof A Olowofoyeku (The African Chief) wrote:
But GPC accepts this: function b(i, j: integer) : a; begin result.i := i; result.j := j end;
So, GPC is nearly there already.
Not really. The case with result-variables, whether implicit (`Result' in Delphi) or explicit (in EP etc.), is quite clear because they always have the same meaning.
The question is the interpretation of the function-identifier in absence of a result-variable. It can either be a recursive call or the assignment of the function result.
The ISO standards are clear (AFAICS) that only if the function-identifier is the direct target of an assignment-statement, it's the assignment of the function result.
BP seems to extend this to cases such as `function-identifier[index]' and (Delphi) `function-identifier.fieldname' which are somewhat harmless because they'd be invalid otherwise (expressions that are no "lvalues" can't occur at the beginning of a statement).
I don't know what the exact rules are that BP uses. Perhaps it assumes that whenever the function-identifier appears at the beginning of a statement, it's meant as the assignment of (a component of) the function result.
This rule becomes wrong in cases such as `function-identifier^', when compared to Pascal semantics, because `function-identifier^' is an lvalue and is therefore a valid beginning of an assignment-statement involving a recursive call. As you reported, Delphi doesn't do it anymore.
Anyway, before deciding what to do, we'll have to know how other compilers behave exactly. Since BP has restrictions on result types, there aren't much cases that can occur (strings and pointers may be the only questionable ones).
In Delphi, as in GPC, function result types can be almost anything, so we'll need to know in which cases it's meant to be the assignment of the function result. Perhaps if the target of an assignment-statement is a function-identifier followed by a sequence of index (`[...]') and component access (`.field') specifications (but not pointer dereferences (`^'))? It may take a series of tests to find out ...
When this is cleared, it'll be another question if we can and/or want to implement it in GPC ...
Frank