★ APPLICATIONS ★ PROGRAMMATION ★ HISOFT PASCAL 464 (PASCAL 4D/4T) ★ |
HISOFT PASCAL 464 (PASCAL 4D/4T) (Popular Computing Weekly) | PASCAL 4D/T (c) HISOFT (Amstrad Computer User) | HISOFT PASCAL 464 (PASCAL 4D/4T) (Home Computing Weekly) |
Pascal is to BASIC what the Amstrad micros are to the Sinclair Spectrum -neater, smarter, more complete but with, as yet, fewer users. Both languages were originally intended as 'models'for teaching computing, but each adopts a completely different design philosophy, which can make it hard to swap from one to the other. This is a shame, as Pascal in general (and HiSoft 4T/D in particular) is a very powerful, compiled language, which runs many times faster than even Locomotive BASIC. BASIC was designed to make computing as easy as possible to learn, by allowing the programmer to do things exactly as he/she wanted. Pascal, on the other hand, encourages the novice programmer to follow 'proper' programming constraints by imposing strict syntax and structure checks on the programs that are compiled. This can be a bit irritating at first, as when you recompile a ten line program for the eighth time because you've forgotten yet another semi-colon. After a while, though, you begin to appreciate what you can do with the language. As the months go by, you become more and more thankful for the Pascal philosophy which forced you to set your program out in a readable way. When you come to revise an old Pascal program you can see what you did in the first place, and can usually graft on the necessary extension without having to rewrite the program from scratch. HiSoft Pascal 4T/D (T stands for the Tape and 'D' for the Disc versions) is the only version of the language available under AMSDOS, although there are several versions (including HiSoft's Pascal 80) which run under CP/M. It is supplied as a cassette or disc, together with a manual. The manual is very much a reference guide. It makes no attempt to teach you the language, and for this you have to buy a tutorial book, or the 'tape and text' approach of HiSoft's own 'Guide to Pascal'. The combined cost of the language and the tutorial package is quite high, and it's a shame the decision was not taken to bundle the two together as a complete package, at a lower cost. That said, the information supplied is very succinct and complete. The reference guide, which runs to nearly 100 pages, contains instructions in the use of the compiler, syntax diagrams of the complete HiSoft implementation, descriptions of the pre-defined identifiers, details of the line editor and a description of the turtle graphics supplied with the package. Appendices describing compiler and run-time error messages, offer some example programs and provide a library of functions and procedures. This library contains routines to mimic most of the useful features available through Locomotive BASIC, and several which are only available via calls to the operating system. This is an extremely valuable extension to the language in its own right. The tape and text tutorial works well, providing plenty of sample Pascal source code and progressing steadily through from first principles. I felt a couple of topics were out of their best order, but generally found the text very useful. It is labelled as 'part 1', and among other things, there is no coverage of graphics or records within it, so I imagine there will be a second volume. I hope the price won't be doubled as well. HiSoft Pascal is a fast implementation of the language specified in the original 'Pascal Report' produced by Jensen and Wirth. Nicklaus Wirth (pronounced 'virt' by his friends) was the originator of Pascal, so you can gather that HiSoft's version is close to what was originally intended for the language. The extensions added to make use of the Amstrad's features are provided as pre-defined functions or in the library routines, so the basic language can remain true to the Jensen/Wirth standard. The only features missing from this implementation are variant RECORDs, the use of FUNCTIONSs and PROCEDURES as parameters and the lack of same filing routines. Turtle graphics are more often associated with the language Logo than with Pascal, and provide an easy way of constructing complex geometric figures on the screen. In Logo, which is an interpreted language and subsequently quite slow in operation, these drawings take a while to create. In Pascal, though, they run very quickly and can be used to great effect in many different applications. The inclusion of the turtle graphics package in HiSoft Pascal is a considerable bonus. HiSoft Pascal allows you easy access to the registers of the Z80 processor, by providing a series of pre-defined Pascal variables which can be used to load the registers before an operating system call, and to read the results from them after the call has been made. The line editor provided with the package is very reminiscent of the Locomotive BASIC editor with which most Amstrad users should be familiar. You can insert and delete lines in the same way as with BASIC, and the editor will renumber them for you on request. You can use the copy cursor to revise lines of program, or type 'E n', where n is the required line number, and edit the line directly. This, again should raise no eyebrows amongst Amstrad users. All HiSoft editor commands are called by a single letter, and as well as the obvious 'E' for edit, T for insert, 'D' for delete and h' for list, there are a number of extra features not available to the Locomotive BASIC programmer. These include 'M' to move a block of code (the program will automatically be renumbered if the 'moved'section is to overwrite existing lines), and 'F' to find a string within the text of a program, and replace it with another, if specified. There are also functions to save and load a program and to print it out. The line numbers attached to the program, which is usually called the 'source' file, are purely for your convenience. Pascal doesn't include GOSUB or GOTO statements with line numbers as their operands, and so has no need of the numbers. They are useful for reference, however. When you compile the program, the line numbers are ignored by the compiler. Before you can run a HiSoft Pascal program, you have to compile it into a machine-code 'object' file. This is done by typing 'C' for compile. The program will then be listed out, line by line, as it's compiled; and any errors that the compiler detects will be signalled with an arrow pointing to the offending area of the line, and an error number telling you what the trouble is. The number has to be translated into a corresponding message via one of the appendices in the reference manual, and you can then re-enter the editor to correct the mistake. In compiled languages a single error, particularly if in the syntax of a line, can cause a number of'spurious'errors to be generated further on, so HiSoft make their compiler stop at each error, to give you the chance to edit the program before proceeding. The HiSoft compiler offers a number of options, so you can tailor the process to your own needs. Most of these options cover various 'checks'that the compiler may make, including arithmetic overflow and array indices within range. You can also select the inclusion of other Pascal source files from tape or disc. This means you can build up a program from predefined sections, stored as separate text files. When you eventually get your program to compile successfully, you are prompted with 'Run?', which is one of the nicest prompts you'll see while developing a Pascal program. If you answer 'Y', the program runs and you can begin to see the extra speed Pascal produces. As an example of how easy it is to use HiSoft Pascal on the Amstrad machines, look at the program listing in Fig. 1. This shows a short Pascal program which will calculate and display a month's calendar for any month between January 1901 and December 1999. It makes use of two library routines, to set the cursor (equivalent to BASIC'S 'LOCATE' command) and define a text window (equivalent to 'WINDOW'), and the rest is fairly straight forward Pascal. Fig 1-EXAMPLE PROGRAM IN HI-SOFT PASCAL All HiSoft Pascal keywords have to be entered in upper case; the compiler will not convert them for you as the Locomotive interpreter does. A brief run-through of the program may help to throw off some of your worries about learning a new language. Apart from remembering that variables and procedures must be specifically declared before they are referred to in the program, and that all individual statements must end with a semi-colon, Pascal's not that difficult to get used to. The first line of any Pascal program must state 'PROGRAM', and give it a name. This will usually be followed by the definition of the 'global'variables used within it. These are defined at the start, so the compiler can make space for them in memory, and doesn't have to worry about new ones being introduced later on (except for 'local'variables used in FUNCTIONS and PROCEDURES). The types of the variables are also declared, and in this program they are all INTEGERS Two library PROCEDURES are the only ones used in this program. A PROCEDURE is similar to a BASIC subroutine, except that it's called by name and can have values ('parameters') passed to it from the program that calls it. The parameters are enclosed in brackets, after the name of the PROCEDURE, and, in this case, also have their types defined as INTEGER. A FUNCTION is much like a PROCEDURE, except that a value is returned to the program that calls it, again like a BASIC 'FN' call. The statements which make up a Pascal PROCEDURE, FUNCTION or the main body of the program are enclosed between a 'BEGIN' and 'END' statement. As well as dividing up the program neatly, they allow multi-line 'IF....THEN....ELSE' clauses. Pascal also has the 'FOR...TO...DO', 'WHILE.. DO' and 'REPEAT...UNTIL' loops. The 'REPEAT...UNTIL' clause is like a 'WHILE...DO' clause, except that the conditional test is made at the end of the loop, rather than the beginning. The program starts by filling the array'm', which was defined at the start, with the number of days in each month of the year. The screen is then cleared and the month and year are entered by the user of the program. The program as listed includes no error checking on these entries. The day of the week of the first day of the required month and year is calculated in two stages. To start, the day of the week of the first of January is worked out, and then the lengths of each month, held in array'm', are added to it to arrive at the first day of the correct month and year. The calendar is displayed by defining a text window just wide enough for seven numbers and displaying the full month, starting on the right day. Each computation is virtually instantaneous, taking only as long as is needed to display the answer. The program itself is concise and easy to read because of the imposed structure and syntax of Pascal. It could have been broken down into smaller units by separating the keyboard entry, calculation and display functions into separate PROCEDURE'S, but is probably short enough as it stands to remain intelligible. CONCLUSION HiSoft Pascal 4T/D is a fast efficient implementation of Pascal which compiles to Z80 object code. This code may then be used on other machines without the compiler installed, providing the opportunity for commercial sales of programs written with it. The speed of HiSoft Pascal, in comparison with BASIC, makes it a very attractive language in which to write, particularly since many of the commands and structures are quite similar, at least in appearance, to their BASIC counterparts. The addition of Amstrad-specific procedures, easy access to the operating system and the inclusion of the turtle graphics package make this version of Pascal very attractive to anyone considering a second language to run on their micro. It can be thoroughly recommended. ACU #8511 |
|