Jump to content

CAL (programming language)

From Wikipedia, the free encyclopedia

Template:Short description CAL, short for Conversational Algebraic Language, was a programming language and system designed and developed by Butler Lampson at Berkeley in 1967 for the SDS 940 mainframe computer. CAL is a version of the seminal JOSS language with several cleanups and new features to take advantage of the SDS platform.

The Berkeley SDS was used for the development of the Tymshare commercial time-sharing platform and an improved version of CAL was offered as a programming environment to its customers in 1969. Although CAL saw "almost no use", it had a lasting impact by influencing the design of Tymshare SUPER BASIC which copied a number of its features. Some of those features, in turn, appeared in BASIC-PLUS on the PDP-11, which is the direct ancestor of Microsoft BASIC.[1]

Description

Basic concepts

JOSS had been designed to be used by non-programmers in the US Air Force and within Rand Corporation, and to aid with that, Rand designed to custom computer terminals that were easier to set up and use. These terminals, based on the IBM Selectric typewriter, also included a custom character set that implemented common mathematical symbols like <syntaxhighlight lang="text" class="" style="" inline="1">≥</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">≠</syntaxhighlight>.

To a large degree, CAL was a version of JOSS that replaced these sorts of customizations with more common solutions like <syntaxhighlight lang="text" class="" style="" inline="1">>=</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">#</syntaxhighlight> so they could run on common terminals.Template:Sfn The other noticeable differences were that CAL was all upper-case, as opposed to sentence casing in JOSS, and it did not require a period at the end of the line.Template:Sfn The commands were otherwise almost identical and the overall structure and syntax were the same.

As with JOSS, CAL had an interactive user interface that allowed the user to type in statements in "direct mode" or programs to be run in "indirect mode". In BASIC, the former is more commonly referred to as "immediate mode". Both CAL and JOSS used a two-part line number, known as the part and step, separated by a period, for instance, <syntaxhighlight lang="text" class="" style="" inline="1">1.100</syntaxhighlight> for part 1 step 100. Parts were generally used to group related statements into subroutines. In CAL, the part number could be between 0 and 999999, and the step from 0 to 99999.Template:Sfn

There were two main versions of CAL, released in 1967 and 1969. The following description will be based primarily on the former version unless otherwise noted.

Jumps and subroutines

As in JOSS, CAL supported the <syntaxhighlight lang="text" class="" style="" inline="1">TO</syntaxhighlight> command to branch to a provided part or step, as in <syntaxhighlight lang="text" class="" style="" inline="1">TO PART 3</syntaxhighlight> or <syntaxhighlight lang="text" class="" style="" inline="1">TO STEP 4.5</syntaxhighlight>, and <syntaxhighlight lang="text" class="" style="" inline="1">DO</syntaxhighlight> for subroutine calls, as in <syntaxhighlight lang="text" class="" style="" inline="1">DO PART 9</syntaxhighlight> to perform the entire part, or <syntaxhighlight lang="text" class="" style="" inline="1">DO STEP 5.1</syntaxhighlight> to run that single step and then return. The later syntax was useful when there were many small subroutines as they could be implemented on a single line without an associated <syntaxhighlight lang="text" class="" style="" inline="1">RETURN</syntaxhighlight> or similar concept.Template:Sfn

Conditional branching and assignment

One of the more notable syntactic features of JOSS was the concept of "statement modifiers" which controlled the operation of other statements. JOSS used this for conditional branching.

In most languages, one would write something to the effect of "If this expression is true, then do this...". In JOSS, this order was reversed, and such statements took the form "do this if this is true", for instance, <syntaxhighlight lang="text" class="" style="" inline="1">Type "HELLO" if X=5.</syntaxhighlight>. CAL added some syntactic sugar to this basic concept by adding the new modifier <syntaxhighlight lang="text" class="" style="" inline="1">UNLESS</syntaxhighlight>, which, depending on the context, led to more obvious code; <syntaxhighlight lang="text" class="" style="" inline="1">TYPE "IT IS NOT EQUAL TO FIVE" UNLESS X=5</syntaxhighlight>.Template:Sfn

In JOSS, to assign the value 5 to a variable A if the value of B was larger than 10, and 0 otherwise, the code would be:

Set A=5 if B>10.
Set A=0 if B<=10.

CAL also supported conditional expressions:Template:Sfn

A=IF B>10 THEN 5 ELSE 0

A similar modification was the <syntaxhighlight lang="text" class="" style="" inline="1">WHERE</syntaxhighlight> statement, used to set variables as part of an if or for. It was similar in concept to the if/then/else structure, but could have any number of items. For instance,<syntaxhighlight lang="text" class="" style="" inline="1">=A*B WHERE A=B UNTIL A>20, WHERE A=1 UNTIL A>100</syntaxhighlight>.Template:Sfn

Loops

Looping in JOSS was also controlled by a modifier, the <syntaxhighlight lang="text" class="" style="" inline="1">For</syntaxhighlight>. This used somewhat obscure syntax from FORTRAN; <syntaxhighlight lang="text" class="" style="" inline="1">Type i for i=1(2)10.</syntaxhighlight> runs a loop from 1 to 10 stepping by 2, so it would print 1,3,5,7,9. One could also supply explicit values, <syntaxhighlight lang="text" class="" style="" inline="1">Type i for i=1,5,6,7,10.</syntaxhighlight>, or mix the two, <syntaxhighlight lang="text" class="" style="" inline="1">Type i for i=1,5(1)7,10.</syntaxhighlight>

CAL improved on JOSS' syntax by introducing the <syntaxhighlight lang="text" class="" style="" inline="1">BY</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">TO</syntaxhighlight> keywords, so the equivalent code in CAL would be <syntaxhighlight lang="text" class="" style="" inline="1">TYPE I FOR I=1 BY 2 TO 10</syntaxhighlight>. In JOSS, the parenthesis around the step value was the separator for the two limits, so it could not be made optional. By separating out <syntaxhighlight lang="text" class="" style="" inline="1">TO</syntaxhighlight> the limits became explicit and the <syntaxhighlight lang="text" class="" style="" inline="1">BY</syntaxhighlight> was made optional as assumed to be 1; <syntaxhighlight lang="text" class="" style="" inline="1">TYPE I FOR I=1 TO 10</syntaxhighlight>. As with JOSS, explicit values and ranges could be used; <syntaxhighlight lang="text" class="" style="" inline="1">TYPE I FOR I=1,5 TO 7,10</syntaxhighlight>. CAL further modified the for loop by adding conditional exits, using <syntaxhighlight lang="text" class="" style="" inline="1">WHILE</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">UNTIL</syntaxhighlight>. For instance, <syntaxhighlight lang="text" class="" style="" inline="1">TYPE A FOR A=1 BY 1 WHILE A<=50</syntaxhighlight> or <syntaxhighlight lang="text" class="" style="" inline="1">TYPE B FOR B=1 UNTIL A=50</syntaxhighlight>.Template:Sfn

User-defined functions

JOSS allowed the user to define functions using the <syntaxhighlight lang="text" class="" style="" inline="1">Let</syntaxhighlight> statement. The syntax allowed local variables to be named in the function signature; <syntaxhighlight lang="text" class="" style="" inline="1">Let F(X,Y)=X+Y.</syntaxhighlight> Programs could then call these functions as if they were built-in, <syntaxhighlight lang="text" class="" style="" inline="1">Set A=F(1,5).</syntaxhighlight>

CAL changed <syntaxhighlight lang="text" class="" style="" inline="1">Let</syntaxhighlight> to <syntaxhighlight lang="text" class="" style="" inline="1">DEFINE</syntaxhighlight>, which is much more obvious, and made a more minor change the parameters were passed in using braces instead of parenthesis, so the equivalent definition would be <syntaxhighlight lang="text" class="" style="" inline="1">DEFINE F[X,Y]=X+Y</syntaxhighlight> and called in the same way, <syntaxhighlight lang="text" class="" style="" inline="1">SET A=F[1,5]</syntaxhighlight>.Template:Sfn

A more important change to CAL's functions was the ability to call subroutines from the definitions using <syntaxhighlight lang="text" class="" style="" inline="1">TO</syntaxhighlight>, as in <syntaxhighlight lang="text" class="" style="" inline="1">DEFINE F(X,Y) : TO PART 5</syntaxhighlight>.Template:Efn This left the issue of assigning the resulting calculated value back to the function, which was addressed with the introduction of the <syntaxhighlight lang="text" class="" style="" inline="1">RETURN Z</syntaxhighlight> statement at the end of the part, where Z is the final value to be returned.Template:Sfn

Other changes

CAL included the mathematical functions of JOSS but added several new ones including <syntaxhighlight lang="text" class="" style="" inline="1">ABS</syntaxhighlight>, <syntaxhighlight lang="text" class="" style="" inline="1">TAN</syntaxhighlight>, <syntaxhighlight lang="text" class="" style="" inline="1">ATAN</syntaxhighlight>, and <syntaxhighlight lang="text" class="" style="" inline="1">LOG10</syntaxhighlight>.Template:Sfn It added a new operator as well, <syntaxhighlight lang="text" class="" style="" inline="1">MOD</syntaxhighlight>, which returned the remainder of a division of its two operands.Template:Sfn

Direct mode

CAL added a small number of direct mode commands and associated statements.

<syntaxhighlight lang="text" class="" style="" inline="1">PAUSE</syntaxhighlight>, when encountered in a program, printed a message "PAUSED AT STEP 1.1" and then returned to direct mode. This was similar to the <syntaxhighlight lang="text" class="" style="" inline="1">STOP</syntaxhighlight> command in BASIC. This allowed the user to type in values and continue execution with <syntaxhighlight lang="text" class="" style="" inline="1">GO</syntaxhighlight>.Template:Sfn While in direct mode, the user could <syntaxhighlight lang="text" class="" style="" inline="1">STEP</syntaxhighlight> by a single line at a time to trace the execution of the program.Template:Sfn

Improvements in CAL 1969

One minor change in the 1969 version was the elimination of the <syntaxhighlight lang="text" class="" style="" inline="1">SET</syntaxhighlight> command for variable assignment. This had been optional in direct mode in JOSS but was required in program statements, and the 1967 version of CAL followed this rule.Template:Sfn The 1969 version made it optional in both cases.

Footnotes

Template:Notelist

References

Citations

Template:Reflist

Bibliography