info-mac@uw-beaver (info-mac) (11/10/84)
From: Stuart Reges <REGES@SU-SCORE.ARPA> Standard Pascal says that there is no constant corresponding to the following string variable: VAR OneChar: PACKED ARRAY [1..1] OF CHAR; That is because the language does not want to confuse strings with type CHAR. The MacPascal documentation tells you that as an extension to the language they provide you with string constants of length 1. The better thing to say would have been, "Strings and type CHAR are now compatible types." I noticed this when a student showed me the following IF/THEN/ELSE: IF ch = ' A' THEN OneThing ELSE AnotherThing; The problem here is the fact that I am comparing ch (of type CHAR) with a string variable of length 2 (because there is a stray space before the A). The student was confused when the OBSERVATION window showed the variable CH with the value 'A' but MacPascal was executing the ELSE branch. This is another of those places where proportional spacing proved to be a pain. The space above is much more visible than it is in MacPascal. This should have been flagged as a type conflict of operands. Before I cover ARRAYs in my course I like to have students see what they can do by manipulating a file character by character. For example, you might want to uppercase an entire file by saying: PROGRAM UpperCase (INPUT, OUTPU); VAR ch: CHAR; BEGIN WHILE NOT EOF DO BEGIN WHILE NOT EOLN DO BEGIN READ (ch); IF ch IN ['a'..'z'] THEN ch := CHR (ORD (ch) - ORD ('a') + ORD ('A')); WRITE (ch) END; READLN; WRITELN END END. I don't suggest using this program in MacPascal. First of all, INPUT and OUTPUT are assigned to the terminal, so you have to explicitely CLOSE them and then RESET and REWRITE to other files. Even so, this program is painfully slow even on input files of just a few thousand characters. I just ran a sample execution on a 2000 character file and found that it took 11.5 minutes. -------