At 10:08 -0400 24/7/05, CBFalconer wrote:
Peter N Lewis wrote:
At 6:34 -0400 24/7/05, CBFalconer wrote:
To start with, new is a standard PROCEDURE, not a function.
New (builtin) is both a procedure and a function. From the documentation:
That is simply wrong. See section 6.7.5.3 of ISO 10206.
If you wish to contradict my statements when I quote both the GPC documentation, and a sample program that GPC compiles, you are free to do so but I cannot see it being overly helpful.
I'm not talking about overriding the New builtin. It is not possible to write a procedure with the semantics of the builtin New in Pascal (this has always seemed a weakness of Pascal to me, that it includes procedures like WriteLn and New that cannot actually be written in the language, but that is more a philosophical question).
I am sure you are talking about the apparent variadic nature of writeln, which does not exist.
My statement is that Pascal includes procedures like New and WriteLn that cannot be themselves written in Pascal, and that I consider this a weakness. There are three parts to that statement:
1. Pascal includes procedures like New and WriteLn. 2. Procedures like New and WriteLn cannot be written in Pascal. 3. I consider this a weakness.
It seems you have chosen to argue against 2. Now perhaps it is unclear as to what I mean by "like", but I would have thought it was fairly clear that a procedure "like" New would be one that could take any of the possible inputs New can take (same syntactic behaviour) and produce the same result (same semantic behavior).
Clearly you can write code that has the same semantic behaviour as WriteLn by expanding it sufficiently into multiple calls to multiple different procedures for each possible type. But that is not "like" WriteLn in that it is not even close to syntactically the same.
You can also write code that has the same semantic behaviour as New(StringPtr,57), as shown by Frank in one of his very helpful answers on how to pack strings together. But again you'd have to write a procedure for each possible type.
I would contend, with a definition of "like" that is "has the same (or even close) syntactic behaviour and same semantic behaviour", that points 1 and 2 are undisputable. Point 3 is clearly undisputable - subject to change perhaps, but undisputable.
No philosophy is required.
The philosophy I refer to is that things that look like functions or procedures in the language should be possible to be written in the language. I consider this a worthy goal and hence a weakness in the language. The problem can be solved in a number of ways:
1. Support types as first class objects and support variable numbers of parameters. 2. Dont support procedures that cannot be written in the language.
Neither of these are standard Pascal of course, because as I said, this is a philosophical point. It is about language design, not Pascal in particular, except for my consideration that this is a weakness in Pascal, for which each person can have their own opinion.
Clearly I don't believe that 2 would be an improvement to Pascal, as the reason for my bringing up this topic is to try to find a way where I can safely use New (and hence get all of the nice Schema advantages with simplicity) in cases where memory allocation might fail.
As for 1, it is well outside the scope of Pascal. Certainly, it could be added to Pascal, and its addition, if well thought out, could make for a benefit to programmers, but obviously I'm not suggesting we rush off and do this. Indeed, I cannot see ever doing this with Pascal.
That leaves Pascal, as it is, with its weaknesses intact. I still consider Pascal to be about the best programming language there is, but that does not mean I don't consider some of its design decisions to be less than optimal. Peter.