Oops! I'm sorry, the example I gave wasn't quite right! :-(
Below is a corrected example, which I hope is both correct (per J&W) and illustrates why this insecurity was changed when Pascal was standardized :
program test; .... procedure fred (function smith : integer); var dummy : integer; begin {fred} dummy := smith('A') end; {fred} .... function one (x : boolean) : integer; .... function two (x, y : integer) : integer; .... begin {test} .... fred(one); .... fred(two); .... end. {test}
As you can see, when the procedure "fred" is compiled, the compiler does not know how many parameters "smith" has, nor what type they are. This makes it difficult for the compiler to validate the program, and just imagine what will happen to the stack - yuck! <g>
Joe.
-----Original Message----- From: Frank Heckenbach [SMTP:frank@g-n-u.de] Sent: Monday, October 22, 2001 11:03 PM To: gpc@gnu.de Subject: Re: Errors and Standards (was: compiler bug)
da Silva, Joe wrote:
Well, from memory, a procedure or function parameter in J&W looked something like the following example :
program test; .... procedure fred (function smith : integer); .... function one (x : boolean) : integer; .... function two (x, y : integer) : integer; .... begin {test} .... fred(one(true)); .... fred(two(1,2)); .... end. {test}
Notice how the formal parameter in procedure "fred" is a function ("smith") of known type (integer) but unknown parameters? Dr. Wirth later decided this was unsafe, so when the ISO-7185 standard was formalised, this was changed (now the formal parameter, function "smith", must show it's formal parameters too). This also applies to ISO-10206, of course.
Do you mean the parameters given to the inner function (one, two) are already specified when calling the outer one (fred)? In this case, it's not much different than making smith type Integer, and passing the function result to fred. (Sure, there could be a difference in when and whether at all one/two are called, but unless they have side-effects, the result will be the same.)
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/ GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html
da Silva, Joe wrote:
Oops! I'm sorry, the example I gave wasn't quite right! :-(
Below is a corrected example, which I hope is both correct (per J&W) and illustrates why this insecurity was changed when Pascal was standardized :
program test; .... procedure fred (function smith : integer); var dummy : integer; begin {fred} dummy := smith('A') end; {fred} .... function one (x : boolean) : integer; .... function two (x, y : integer) : integer; .... begin {test} .... fred(one); .... fred(two); .... end. {test}
As you can see, when the procedure "fred" is compiled, the compiler does not know how many parameters "smith" has, nor what type they are. This makes it difficult for the compiler to validate the program, and just imagine what will happen to the stack - yuck! <g>
Oh dear, then it's really as bad as I'd feared. So I think we won't introduce `--wirth-pascal' in GPC anytime soon. ;-)
Does anyone know why this was so? Wirth must certainly have noticed the problem. Was he just afraid of the nested parentheses in a SP-like declaration with parameters?
Frank