home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / da / abccalc.sit / ABCcalc.doc.text < prev    next >
Text File  |  1987-03-19  |  12KB  |  125 lines

  1. Ñ The ABC Calculator, version 1.0
  2. Copyrighted freeware by Guido van Rossum.
  3.    Ñ Copyright Notice
  4. 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.
  5.    Ñ Introduction
  6.       Ñ 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.
  7. For example, if you type '2**100-1' and press the Enter key, the following result is displayed below your input:
  8. 1267650600228229401496703205375
  9. 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.
  10. It is possible to assign values to names and use the names thus defined in further calculations.  There are no other programming features.
  11.    Ñ Expressions
  12.       Ñ Notation used
  13. 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.
  14.          ╫ non-terminal: form
  15. 'form' is the definition for 'non-terminal'
  16.          ╫ list | list | ...
  17. separates alternatives
  18.          ╫ item*
  19. 0 or more repetitions of 'item'
  20.          ╫ item+
  21. 1 or more repetitions of 'item'
  22.          ╫ [ item ... ]
  23. 'item...' are optional
  24.          ╫ ( item ... )
  25. used for grouping
  26.          ╫ ' characters '
  27. characters between single quotes are literals
  28.       Ñ (Simplified) formal syntax
  29. This doesn't show the priorities for operators (see next section).
  30.          ╫ statement:    assignment | expression
  31.          ╫ assignment:    name '=' statement
  32.          ╫ expression:    term ( dyadic-operator term )*
  33.          ╫ term:    monadic-operator* operand
  34.          ╫ operand:    name | number | '(' statement ')'
  35.          ╫ name:    letter ( letter | digit | '_' )*
  36.          ╫ number:    digit+ [ '.' digit* ] [exponent] | '.' digit+ [exponent]
  37.          ╫ exponent:    ( 'e' | 'E' ) [ '+' | '-' ] digit+
  38.          ╫ monadic-operator:    '+' | '-' | '*/' | '/*' | 'floor' | 'round'
  39.          ╫ dyadic-operator:    '+' | '-' | '*' | '/' | '**' | 'mod' | 'round'
  40.          ╫ letter: 'a' | 'b' | ... | 'z'
  41.          ╫ digit: '0' | '1' | ... | '9'
  42.          ╫ (Note that only lower case letters are allowed in names).
  43.       Ñ Lexical conventions
  44.          ╫ Spaces may be inserted everywhere except within names, numbers or operators.
  45.          ╫ When a name or number is adjacent to another name or number in the grammar, at least one space is necessary to separate them.
  46.       Ñ Priorities of operators
  47.          ╫ 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.
  48.       Ñ Description of operators
  49.          ╫ 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.
  50.          ╫ Traditional arithmetic
  51.             ╫ 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.
  52.             ╫ 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).)
  53.             ╫ */x yields the numerator of x's representation (see above).  This is an integer with the same sign as x.
  54.             ╫ /*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.)
  55.             ╫ 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.
  56.             ╫ 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.)
  57.             ╫ 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.
  58.             ╫ 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.
  59.    Ñ Output
  60.       Ñ 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.
  61.       Ñ 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 '~'.
  62.       Ñ Examples:
  63.          ╫ 0.2**100
  64. .0000000000000000000000000000000000000000000000000000000000000000000001267650600228229401496703205376
  65.          ╫ 1/3
  66. ~.33333333333333333333
  67.          ╫ 1/7000
  68. ~.00014285714285714285714
  69.          ╫ 1000000000/13
  70. ~76923076.9230769230769
  71.          ╫ 10**100/13
  72. ~769230769230769230769230769230769230769230769230769230769230769230769230769230769230769230769230769
  73.          ╫ 50 round (1/13)
  74. .07692307692307692307692307692307692307692307692308
  75.    Ñ Editing operations
  76.       Ñ The following keys are used to edit the text in the window:
  77.       Ñ Cmd-X, Cmd-C, Cmd-V for Cut, Copy, Paste
  78.       Ñ Cmd-A for Select All
  79.       Ñ Backspace and Clear have the usual meaning
  80.       Ñ Return just inserts a line feed in the text
  81.       Ñ Enter executes the current selection, or the current line if the selection is empty
  82.       Ñ Cmd-. interrupts calculations (see below)
  83.    Ñ The menu
  84.       Ñ When the calculator's window is active, a menu named ABC appears in the menu bar.  This menu provides file and font operations.
  85.       Ñ File operations are the following standard functions: New, Open, Save, Save as, Save a Copy, and Revert to Saved.
  86.       Ñ 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.
  87.    Ñ Interrupting calculations
  88.       Ñ 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).
  89.    Ñ Bugs, caveats and deficiencies
  90.       Ñ Compatibility with older Macs
  91.          ╫ On Macs with 'old' ROMs (unupgraded Mac 512K, Mac 128K and Mac XL (Lisa)), certain features don't work:
  92.          ╫ 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.
  93.          ╫ The window doesn't auto-scroll while dragging the mouse outside the window boundaries.
  94.          ╫ Output of numbers that don't fit on a line is very slow.
  95.          ╫ 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 +.
  96.          ╫ The list of fonts in the menu is usually too long to be displayed without scrolling.
  97.       Ñ Memory problems
  98.          ╫ Numbers of about 5000 digits or more will cause a crash when output, because the output buffer is only that large.
  99.          ╫ 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.
  100.       Ñ User interface deficiencies
  101.          ╫ There is no 'Undo'.
  102.          ╫ When interrupts are being checked for, type-ahead is thrown away.
  103.          ╫ 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.)
  104.          ╫ The error message for syntax errors is not very informative: there is no indication of where the error occurred.
  105.          ╫ 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.)
  106.          ╫ Now that there is a save possibility, it insists on asking whether the document should be saved before closing.
  107.       Ñ Missing capabilities
  108.          ╫ There are no transcendental functions (because these would require a representation for approximate numbers).
  109.          ╫ The 'programming features' should be extended with function definitions, loops, arrays and if-then-else constructs.
  110.    Ñ The ABC Programming Language
  111.       Ñ 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.
  112.       Ñ ABC is a structured programming language designed at the Center for Mathematics and Computer Science (CWI) in Amsterdam, The Netherlands.
  113.       Ñ 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.
  114.       Ñ 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.
  115.       Ñ 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.
  116.    Ñ Author's address:
  117.       Ñ Guido van Rossum,
  118. CWI, dept. AA,
  119. Kruislaan 413,
  120. 1098 SJ  Amsterdam,
  121. The Netherlands.
  122.       Ñ Electronic mail (Internet or UUCP):
  123. guido@cwi.nl, or guido@mcvax.uucp (old form).
  124. From the ARPAnet, if neither of these work, try guido%cwi.nl@seismo.
  125.