|
From: | Fischlin Andreas |
Subject: | Re: proctype and procedure type checking fully implemented |
Date: | Sun, 21 Apr 2024 13:04:00 +0000 |
Hi all, I am having difficulties to follow what you try to convey. Perhaps my thoughts below help to clarify A code such as
as most likely intended is first of all "syntactically wrong", as it should be written as If written in this manner, it should be accepted by the compiler, regardless whether the actual argument of WriteCard is a value returned by a function procedure or a variable or a constant. Perhaps we do not disagree here, do we? However, I find the error message far from helpful. Assignment compatibility should be referred to here and not referring to a rather vague formal and actual parameter incompatibility. Following assignments are implicit here assuming
and WriteCard (func(), 5) implies assignment x := func(); In the first case you assign the procedure function ‘func', not its result, to x and it becomes obvious that procedure type FuncType is not assignment compatible with CARDINAL. In the 2nd case you assign the result returned by the function ‘func’ to x and only the type of the result returned by func must be assignment compatible with x. Therefore, I would suggest to reformulate the error message to something similar to this Type of actual parameter ‘func’ is not assignment compatible with the corresponding formal parameter of ‘WriteCard’ This would be a very generic error message that may not always help the programmer to understand what the mistake was, e.g. WriteCard (func, 5) written but meant WriteCard (func(), 5) and therefore some case distinction as described below may be more appropriate than above too generic error message. Your example WriteCard (func, 5) would then lead to following compile time error message Procedure type of ‘func’ is not assignment compatible with the corresponding formal parameter of ‘WriteCard’ Something like PROCEDURE func () : BOOLEAN ; BEING ... and a statement such as WriteCard (func(), 5) should also lead to a compilation error message. Then the compiler error message could perhaps be similar to Type returned by ‘func’ is not assignment compatible with the corresponding formal parameter of ‘WriteCard’ to avoid using the too generic error message I mentioned first. Then I assume we are talking only about compile time errors, right? So a function procedure such as PROCEDURE func () : INTEGER ; BEING ... is accepted by the compiler with WriteCard (func(), 5) and leads at most to a runtime error, e.g. if func would return a negative value. BTW, the ident of the function procedure ‘func' would profit from being written capitalized as ‘Func’. Only for a MathLib module I might tolerate lower case function procedure idents such as ’sin’, ‘cos’ as only those are established math idents. But this is irrelevant, it is just hard to read for me and against all my habits while programming in M2. ;-) Regards, Andreas ETH Zurich Prof. em. Dr. Andreas Fischlin Systems Ecology - Institute of Biogeochemistry and Pollutant Dynamics CHN E 24 Universitaetstrasse 16 8092 Zurich SWITZERLAND +41 44 633-6090 phone +41 79 595-4050 mobile Make it as simple as possible, but distrust it! ________________________________________________________________________
|
smime.p7s
Description: S/MIME cryptographic signature
[Prev in Thread] | Current Thread | [Next in Thread] |