The nightmare of Sharp Pascal

One of the Sharp MZ-80K’s more unusual features was that it didn’t come with BASIC pre-installed in read-only memory like similar computers of the time. Instead, one of the first things you had to do after switching on was load the language you wanted to use from tape. The BASIC provided with the machine took around 2.5 minutes to load. While inconvenient, it did mean that other programming languages were available.

In 1981 I made the decision to study Computer Science at university. Warwick was my first choice, and they taught their first year students the joys and woes of structured programming using Pascal. I had a regular Saturday job at a local garden centre and a shiny new bank account. So the first cheque I ever wrote was for £50 or so to Knight’s Computers in Aberdeen for a copy of the Sharp SP-4015 Pascal interpreter. The second was probably for Warwick’s recommended textbook – Oh! Pascal! by Cooper and Clancy.

I uncovered the Sharp tape and manual while I was renovating the MZ-80K a few weeks ago. I’ve since had a chance to play with the Pascal interpreter again. The experience reminded me why I stuck with BASIC for programming it.

The first horror is the editing environment. Unlike the BASIC interpreter, you can’t simply list the program and use the cursor keys to make changes. That would have been far too simple! Instead, Sharp Pascal comes with a line-oriented editor designed to hurt.

Designed to hurt the unwary – the Sharp SP-4015 Pascal Interpreter command summary

The second horror is that to enable the editor, the Sharp Pascal interpreter makes use of line numbers. They don’t affect program control (there’s no goto and label construct) – they’re simply there to facilitate the editor. Confusing, to say the least.

The third horror are some of the compromises made in the language to enable it to fit into 48K of memory and still leave a sensible amount of space left for programs (around 31K – so it takes a little more space than the Sharp BASIC interpreter). There’s no program statement. No user defined types. Only one VAR declaration per subprogram is permitted – although you can declare as many variables as you need. Array references can’t be passed to a function or subroutine. Comments are denoted using the % character, rather than { or (*. Declaring an array uses non-standard syntax for no apparent reason. Worst of all is that the interpreter takes a puritanical view of looking after the types it does have that would no doubt please Niklaus Wirth – the inventer of Pascal – no end.

For example, if NUM is an integer, the widely available Free Pascal compiler is perfectly happy with the statement:

IF NUM=3*TRUNC(NUM/3) THEN …

as it implicitly converts NUM and 3 to real numbers when used within the scope of the TRUNC function. In Sharp Pascal, this has to be written as:

IF NUM=3*TRUNC(FLOAT(NUM)/3.0) THEN …

otherwise the interpreter generates an ERR17 message ‘An incorrect type of value is assigned to a variable’.

Anyway, for the record here’s a listing of my BASIC sieve of Eratosthenes prime number generator converted into Sharp Pascal. There’s a special prize for anyone who can work out why lines 43-46 are required and what they do. I also have a more standards compliant implementation written before attempting this version.

Sieve of Eratosthenes in Sharp SP-4015 Pascal