COMAL (Common Algorithmic Language) is a computer programming language developed in Denmark by Børge R. Christensen and Benedict Løfstedt and originally released in 1975. It was based on the BASIC programming language, adding multi-line statements and well-defined subroutines among other additions.

COMAL was originally written for minicomputers, but was small enough to run on early microcomputers as well. It is one of the few structured programming languages that were available for and comfortably usable on 8-bit home computers.

"COMAL Kernel Syntax & Semantics" contains the formal definition of the language.

Description

COMAL was created as a mixture of the prevalent educational programming languages of the time, BASIC, Pascal, and, at least in the Commodore and Compis versions, the turtle graphics of Logo. The language was meant to introduce structured programming elements in an environment where BASIC would normally be used.

In early versions, the primary additions to the language were block versions of IF...THEN, and the PROC construct. In most previous versions of BASIC, the only block construct was the FOR...NEXT loop. For instance:

<syntaxhighlight lang="comal">

10 FOR I=1 TO 10

20 PRINT I

30 J=J+1

40 NEXT I

</syntaxhighlight>

This example performs a loop ten times, and performs two instructions every time through the loop. In contrast, almost every other instruction in BASIC, or statement, has to be accomplished on a single line. This can make multi-line statements difficult to perform on an all-or-nothing basis. For instance, if a program desires to run three instructions if a particular value is greater than 10, the typical solution is:

<syntaxhighlight lang="comal">

10 IF A<=10 THEN 50

20 PRINT "A IS GREATER THAN 10"

30 A=A+10

40 PRINT "A IS NOW ";A

50 PRINT "RETURNING TO OUR REGULARLY SCHEDULED PROGRAMMING"

</syntaxhighlight>

This sort of construct hides the true intention of the program, the decision is based on the opposite logic of what the programmer actually wants to accomplish. Additionally, to understand what will happen in this case, the reader has to find line 50, which in real programs might be much further into the source code. This is one of the major reasons that BASIC programs are referred to as "spaghetti code", as to follow the logic one moves around the program as if following a series of random spaghetti noodles.

COMAL addresses this issue through the use of blocks. To accomplish this same series of instructions, in COMAL one would write:

<syntaxhighlight lang="comal">

10 IF A>10 THEN

20 PRINT "A IS GREATER THAN 10"

30 A=A+10

40 PRINT "A IS NOW ";A

50 ENDIF

60 PRINT "RETURNING TO OUR REGULARLY SCHEDULED PROGRAMMING"

</syntaxhighlight>

In this case, the author writes the decision they are actually trying to accomplish, and the reader can follow the logic simply by looking for the . This is aided by COMAL's use of leading spaces to visually indicate blocks.

Examples

  • "Hello, world!"
  • :<syntaxhighlight lang="comal">

PRINT "HELLO, WORLD!"

</syntaxhighlight>

  • Conditions
  • :<syntaxhighlight lang="comal">

IF condition THEN

instructions

ENDIF

</syntaxhighlight>

  • Loops
  • :<syntaxhighlight lang="comal">

FOR number:= 1 TO 1000 DO

PRINT number

ENDFOR

</syntaxhighlight>

  • Print statements with variables
  • :<syntaxhighlight lang="comal">

INPUT "What's your favourite number? " :nmr#

PAGE

PRINT "Your favourite number is " ; nmr#

</syntaxhighlight>

Availability

COMAL was available for:

  • BBC Micro
  • Commodore PET
  • Commodore 64
  • Commodore 128
  • Amiga
  • Compis/Scandis
  • CP/M
  • IBM PC

Further reading

  • Thomas Lundy & Rory O'Sullivan: Beginning Structured Programming in BASIC and COMAL, 1990
  • Roy Atherton: Structured programming with COMAL. Horwood, Chichester 1982, .
  • Børge R. Christensen: Beginning Comal. Horwood, Chichester 1982, .
  • Børge R. Christensen: COMAL Reference Guide. Toronto PET Users Group, Toronto Ontario, .
  • Len Lindsay: COMAL handbook. Reston Publishing, Reston, VA, 1983, .
  • Gordon Shigley: COMAL Workbook. Comal Users Group, USA, 1985, .
  • OpenCOMAL for Unix, MS-DOS and Win32
  • A fork of the above for standards-compliant Unix, mainly Linux and Mac OS X
  • UniComal 3.11 packaged to run under DOSBox
  • Description of COMAL, versions, and characteristics (1984)