Compactor
by Julian Wood
from Your Computer, November 1983


Compactor
Julian Wood, Downham Market, Norfolk

If you have ever been typing in a program and suddenly run out of
memory, you will find this Compactor program very useful. The program,
for either ZX Spectrum, compacts almost any BASIC program. A typical
48K program is shortened by about 7K. It normally shortens a program
by about 15% of its original size, but this depends on how many
numbers there are in the program.

Changing each number
The Compactor works by changing each number in a program to its VAL
equivalent. For example, the number 255 would be changed to VAL "255".
This way, each number is shortened by three bytes, as the need for a
CHR$ 14 and the following five bytes is eliminated.

Program is shortened
Because the program is shortened, all the memory from the shortened
number up to ELINE has to be shifted down every time a number is
shortened. Also, the system variables VARS and ELINE have to be altered.

Loading the computer
The Compactor does not affect variables, but it is advisable to CLEAR
any present before calling the Compactor, as this makes the compaction
process faster. As it is essential for the Compactor to be short -
because it is used when memory is short - it was decided not to
include other compaction techniques, such as NOT PI for 0, as this
would increase the length of the Compactor program. As it is, the
Compactor occupies only 122 bytes.


