¥ The ABC Calculator, version 1.0
Copyrighted freeware by Guido van Rossum.
   ¥ Copyright Notice
This software is Copyright © 1987 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands.  It may be freely distributed but not sold for profit, as long as this copyright notice is distributed along with the software.
   ¥ Introduction
      ¥ The ABC calculator differs from most calculators in two areas: first, it carries out all calculations with unlimited precision, and second, its user interface allows free-form input of expressions that resemble the statements of a (very simple) programming language.
For example, if you type '2**100-1' and press the Enter key, the following result is displayed below your input:
1267650600228229401496703205375
The text in the window can be edited freely; only the Enter key triggers calculations.  The normal editing functions (Cut, Copy, Paste, Clear, Select All) are available, but not Undo.
It is possible to assign values to names and use the names thus defined in further calculations.  There are no other programming features.
   ¥ Expressions
      ¥ Notation used
The syntax of expressions is listed here in a modified BNF grammar.  The notation used in this grammar is listed here, from weakest binding to strongest binding construct.
         × non-terminal: form
'form' is the definition for 'non-terminal'
         × list | list | ...
separates alternatives
         × item*
0 or more repetitions of 'item'
         × item+
1 or more repetitions of 'item'
         × [ item ... ]
'item...' are optional
         × ( item ... )
used for grouping
         × ' characters '
characters between single quotes are literals
      ¥ (Simplified) formal syntax
This doesn't show the priorities for operators (see next section).
         × statement:	assignment | expression
         × assignment:	name '=' statement
         × expression:	term ( dyadic-operator term )*
         × term:	monadic-operator* operand
         × operand:	name | number | '(' statement ')'
         × name:	letter ( letter | digit | '_' )*
         × number:	digit+ [ '.' digit* ] [exponent] | '.' digit+ [exponent]
         × exponent:	( 'e' | 'E' ) [ '+' | '-' ] digit+
         × monadic-operator:	'+' | '-' | '*/' | '/*' | 'floor' | 'round'
         × dyadic-operator:	'+' | '-' | '*' | '/' | '**' | 'mod' | 'round'
         × letter: 'a' | 'b' | ... | 'z'
         × digit: '0' | '1' | ... | '9'
         × (Note that only lower case letters are allowed in names).
      ¥ Lexical conventions
         × Spaces may be inserted everywhere except within names, numbers or operators.
         × When a name or number is adjacent to another name or number in the grammar, at least one space is necessary to separate them.
      ¥ Priorities of operators
         × The operators have been given 'priority intervals' which give the expected meaning to expressions like '-a*b+c/d**e' while at the same time ruling out ambiguities such as 'a + b mod c' or 'foo/bar/bletch' and 'x**y**z'.  Although it doesn't show in the syntax given above, unary operators play a role here, too: e.g., 'floor x + y' is illegal.  It's hard to explain the exact rules here in an understandable fashion; be advised to add extra parentheses if an expression doesn't parse.  Especially the arguments of mod, round and floor require parentheses as soon as they're not a single name or number.
      ¥ Description of operators
         × Internally, all numbers are represented as fractions: n/d, where d is a positive integer and n a signed integer.  Before the result of a calculation is stored in this form, common factors of n and d are removed, so 12/-4 will be represented as (-3)/1.  This representation ensures that (1/7)*7 can be computed exactly.  The operators */ and /* access n and d, respectively.
         × Traditional arithmetic
            × The dyadic operations x+y (sum), x-y (difference), x*y (product) and x/y (quotient) are carried out as you would expect.  The monadic operations +x and -x can be derived from their dyadic counterparts by viewing them as 0+x and 0-x.
            × x**y yields x to the power y.  The exponent y must be an integral number (or the result might not be representable as a fraction, as in 2**(1/2).)
            × */x yields the numerator of x's representation (see above).  This is an integer with the same sign as x.
            × /*x yields the denominator of x's representation.  This  is a positive integer.  (*/x) * (/*x) equals x.  (Note the mnemonic form of these operators: the * is on the same side of the / as the value yielded is in x's representation.)
            × floor x yields the largest integer not larger than x.  For example, floor 2.9 is 2, floor 3 is 3, and floor -3.9 is -4.
            × round x yields an integer closest to x, e.g. round 2.2 is 2, round 2.8 is 3, and round -2.2 is -2.  If there are two possibilities, it yields the one with the largest absolute value, so round 2.5 is 3 and round -2.5 is -3.  (In other words, it rounds away from zero.)
            × n round x yields x rounded to n digits; this is the same as (round (x*10**n)) / 10**n.  The value n must be an integral number; it may be negative, so e.g. (-2) round 666 is 700.
            × x mod y yields the remainder after division, as computed by x - y*floor(x/y).  It has the same sign as y and its absolute value is smaller than y's.
   ¥ Output
      ¥ The result of every executed top-level statement is displayed on a new line right after the input, except if is is an assignment.  (The result of an assignment can be printed by surrounding it with parentheses).  The text selection is placed on a new line below the output.
      ¥ If a value can be represented exactly in decimal notation, it is displayed exactly, no matter how many digits are necessary.  Values that can't be represented exactly in the decimal system (such as 22/7) are displayed with at least 20 digits of precision.  Such inexact values are prefixed with a '~'.
      ¥ Examples:
         × 0.2**100
.0000000000000000000000000000000000000000000000000000000000000000000001267650600228229401496703205376
         × 1/3
~.33333333333333333333
         × 1/7000
~.00014285714285714285714
         × 1000000000/13
~76923076.9230769230769
         × 10**100/13
~769230769230769230769230769230769230769230769230769230769230769230769230769230769230769230769230769
         × 50 round (1/13)
.07692307692307692307692307692307692307692307692308
   ¥ Editing operations
      ¥ The following keys are used to edit the text in the window:
      ¥ Cmd-X, Cmd-C, Cmd-V for Cut, Copy, Paste
      ¥ Cmd-A for Select All
      ¥ Backspace and Clear have the usual meaning
      ¥ Return just inserts a line feed in the text
      ¥ Enter executes the current selection, or the current line if the selection is empty
      ¥ Cmd-. interrupts calculations (see below)
   ¥ The menu
      ¥ When the calculator's window is active, a menu named ABC appears in the menu bar.  This menu provides file and font operations.
      ¥ File operations are the following standard functions: New, Open, Save, Save as, Save a Copy, and Revert to Saved.
      ¥ Font and type size selected in the menu affect all text in the calculator's window.  The current font and size are indicated with a check mark, and sizes that can be drawn without font scaling are shown in outline.  Only sizes 9, 10, 12, 14 and 18 are available.  When a font is selected and the current size would require scaling, the smallest non-scaling size is chosen instead.
   ¥ Interrupting calculations
      ¥ Long calculations can be interrupted by pressing Command-period.  This may output a zero or question mark.  'Short' calculations can't be interrupted in this way; the calculator only starts checking for interrupts when the length of intermediate results exceeds a certain limit.  This feature is mostly useful to abort calculations that would take hours or a lifetime to complete without having to reboot the Mac, such as 1.0000001**(2**27).
   ¥ Bugs, caveats and deficiencies
      ¥ Compatibility with older Macs
         × On Macs with 'old' ROMs (unupgraded Mac 512K, Mac 128K and Mac XL (Lisa)), certain features don't work:
         × When typing in the middle of the text (as opposed to at the end), the window does not automatically scroll to keep the caret in view.
         × The window doesn't auto-scroll while dragging the mouse outside the window boundaries.
         × Output of numbers that don't fit on a line is very slow.
         × When used with System file version 2.0 or earlier, the window's grow box is inoperative.  This can be fixed by changing the 'WIND' resource (with ResEdit or another resource editor) to have window type 0 instead of 8.  A version thus fixed won't have a zoom box when moved to the Mac +.
         × The list of fonts in the menu is usually too long to be displayed without scrolling.
      ¥ Memory problems
         × Numbers of about 5000 digits or more will cause a crash when output, because the output buffer is only that large.
         × There are insufficient checks for out-of-memory conditions.  Calculations involving large numbers in a memory-starved environment (as when running applications under Switcher or on a small Mac) may cause unexpected crashes.
      ¥ User interface deficiencies
         × There is no 'Undo'.
         × When interrupts are being checked for, type-ahead is thrown away.
         × Because very long strings of digits are common in the output, lines may be broken anywhere between two digits.  An unfortunate by-product of this is the fact that double-clicking on a number does not select the number.  (This is not done with old ROMs.)
         × The error message for syntax errors is not very informative: there is no indication of where the error occurred.
         × Occasionally, ghost images of the caret (the text insertion point indicator) will remain on the screen.  This appears to be a TextEdit bug (I've seen in happen in miniWRITER, too.)
         × Now that there is a save possibility, it insists on asking whether the document should be saved before closing.
      ¥ Missing capabilities
         × There are no transcendental functions (because these would require a representation for approximate numbers).
         × The 'programming features' should be extended with function definitions, loops, arrays and if-then-else constructs.
   ¥ The ABC Programming Language
      ¥ The expression syntax (except for the form of assignment), the special operators and the semantics (i.e., unlimited precision) of the ABC Calculator have been borrowed from the programming language ABC.
      ¥ ABC is a structured programming language designed at the Center for Mathematics and Computer Science (CWI) in Amsterdam, The Netherlands.
      ¥ ABC is aimed at non-professional programmers, but it has several features that are sorely lacking in many professional programming languages, such as variable-length and associative arrays, and generally very-high-level data structures.  ABC has strict type checking but does not require declarations.  Functions are 'polymorphic', i.e. they apply to different types as long as the operations used by the function apply to the argument types.
      ¥ For a good introduction to ABC, see the article by Steven Pemberton in the January, 1987 issue of IEEE Software; or the following two SIGPLAN issues (where a previous version of the language is described, called 'B', although it is NOT the predecessor of 'C'): December 1982 and February 1985.
      ¥ Implementations of ABC are soon to be available for the Macintosh, the IBM-PC (or clones) and generic Unix systems.  Implementations of ABC's predecessor, 'B', are already available for the same machines.  Write to the author's institute for more information, or for a free subscription to the 'ABC Newsletter' to be kept up-to-date on the subject of ABC.
   ¥ Author's address:
      ¥ Guido van Rossum,
CWI, dept. AA,
Kruislaan 413,
1098 SJ  Amsterdam,
The Netherlands.
      ¥ Electronic mail (Internet or UUCP):
guido@cwi.nl, or guido@mcvax.uucp (old form).
From the ARPAnet, if neither of these work, try guido%cwi.nl@seismo.
