Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
COMAL
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Description == COMAL was created as a mixture of the prevalent educational programming languages of the time, [[BASIC]], [[Pascal (programming language)|Pascal]], and, at least in the [[Commodore International|Commodore]] and [[Compis]] versions, the [[turtle graphics]] of [[Logo (programming language)|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 {{code|ENDIF}}. This is aided by COMAL's use of leading spaces to visually indicate blocks.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)