Frank Heckenbach wrote:
Waldek Hebisch wrote:
Note that in Pascal there is no syntactic dictinction between function used as a value and parameterless function call. I guess that the restriction is intended to reduce resulting confusion -- if context want a function than we use function "as is", if context wants something else we call the function. In fact, any "function producing" expression has the same problem: it is not clear if the resulting function should be called or not (AFAICS the rule above is used).
In fact, the rules are a bit hairy internally, and may not be quite correct in some strange cases. I plan to work on this issue sometime and perhaps reimplement much of it. Maybe we can remove the restriction in this course (perhaps calling the function so often until the type matches), but I don't want to promise too much now.
This may be too eager to choose a call. Look at:
type fp = ^ ft; fp2 = ^ ft; ft = function : fp;
function foo: fp; var x : fp2;
x := fp2 (@foo);
Casts may be quite reasonable to mask "inessential" type incompatibility, but if allowed for procedures will cause spurious calls.
Also, if we choose call the procedural version would not work. We can use empty parentheses to force the call, but I am affraid that we have no way to prevent the call.
I personaly think that procedure variables are more elegant than procedure pointers, but IMHO without a 100% reliable way to prevent call procedure variables just are broken.