Waldek Hebisch wrote:
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.
Yes. Perhaps we could say, inside a cast any pointer type matches, so there's no need to call anything in this example, and therefore we should not call anything. But I'm not sure if that's easy to implement ...
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.
So we should only call when necessary (i.e., types don't match without calling).
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.
My be difficult. If foo is a procedural (or functional) variable, then
bar := foo;
can be a call if bar is of the result type. Of course, you can always do `@foo' (according to BP, this does not give the address of the variable, but casts it to a pointer type). This should always prevent a call AFAICS.
Frank