axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] 20070823.01.tpd.patch applied to silver


From: daly
Subject: [Axiom-developer] 20070823.01.tpd.patch applied to silver
Date: Mon, 27 Aug 2007 02:45:34 -0500

diff --git a/changelog b/changelog
index e981cf7..87548f8 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,5 @@
+20070823 tpd src/doc/spadhelp add additional spadhelp files
+20070823 tpd src/doc/Makefile add additional spadhelp files
 20070822 tpd src/doc/spadhelp add language help
 20070822 tpd src/doc/Makefile add spadhelp
 20070822 tpd src/doc/spadhelp created
diff --git a/src/doc/Makefile.pamphlet b/src/doc/Makefile.pamphlet
index c5af55b..7556528 100644
--- a/src/doc/Makefile.pamphlet
+++ b/src/doc/Makefile.pamphlet
@@ -130,23 +130,28 @@ ${INT}/booklet.c: ${IN}/booklet.c.pamphlet
          
 @
 \section{The )help files}
-<<helpspad>>=
-HELPSPAD=abbreviation boot cd clear close compile display edit fin frame \
-         help history \
-         language library lisp load ltrace \
-         nclef pquit quit read \
-         savesystem set show spool synonym system trace undo what
+This list is the same as the list at the end of the help section
+in spadhelp.pamphlet.
+<<spadhelp>>=
+SPADHELP=\
+abbreviations assignment boot       blocks     cd         clear      \
+clef          close      collection compile    display    edit       \
+fin           for        frame      help       history    if         \
+iterate       leave      library    lisp       load       ltrace     \
+parallel      pquit      quit       read       repeat     savesystem \
+set           show       spool      suchthat   synonym    system     \
+syntax        trace      undo       what       while
 
 @
-<<helpspad.files>>=
-${DVI}/spadhelp/helpspad.files: ${IN}/spadhelp.pamphlet
+<<spadhelp.files>>=
+${DVI}/spadhelp/spadhelp.files: ${IN}/spadhelp.pamphlet
        @echo 9 making ${DVI}/spadhelp from ${IN}/spadhelp.pamphlet
        @mkdir ${DVI}/spadhelp
        @(cd ${DVI}/spadhelp ; \
-          for i in ${HELPSPAD} ; do \
+          for i in ${SPADHELP} ; do \
             ${TANGLE} -R"$$i" ${IN}/spadhelp.pamphlet >$$i.help ; \
           done ; \
-          ls *.help >helpspad.files )
+          ls *.help >spadhelp.files )
 
 @
 \section{The Makefile}
@@ -161,11 +166,11 @@ DOC=${INT}/doc
 
 FILES= ${MID}/axiom.bib ${STY}/axiom.sty ${DVI}/bookvol4.dvi \
        ${DVI}/book.dvi ${DVI}/bookvol1.dvi ${DVI}/endpaper.dvi \
-       ${DVI}/rosetta.dvi ${DVI}/spadhelp/helpspad.files
+       ${DVI}/rosetta.dvi ${DVI}/spadhelp/spadhelp.files
 
 CMDS=${OUT}/booklet
 
-<<helpspad>>
+<<spadhelp>>
 
 all: ${FILES} ${CMDS}
        @echo 9 finished ${IN}
@@ -178,7 +183,7 @@ all: ${FILES} ${CMDS}
 <<bookvol1>>
 <<Endpapers>>
 <<rosetta>>
-<<helpspad.files>>
+<<spadhelp.files>>
 
 
 document:
diff --git a/src/doc/spadhelp.pamphlet b/src/doc/spadhelp.pamphlet
index 77f0027..54ea77c 100644
--- a/src/doc/spadhelp.pamphlet
+++ b/src/doc/spadhelp.pamphlet
@@ -11,8 +11,8 @@ command line )help command.
 \eject
 \tableofcontents
 \eject
-\section{abbreviation}
-<<abbreviation>>=
+\section{command abbreviations}
+<<abbreviations>>=
 ====================================================================
 A.2.  )abbreviation
 ====================================================================
@@ -85,7 +85,163 @@ o )compile
  
 @
 
-\section{boot}
+\section{syntax assignment}
+<<assignment>>=
+
+Immediate, Delayed, and Multiple Assignment
+
+====================================================================
+Immediate Assignment
+====================================================================
+
+A variable in Axiom refers to a value. A variable has a name beginning
+with an uppercase or lowercase alphabetic character, "%", or "!".
+Successive characters (if any) can be any of the above, digits, or "?".
+Case is distinguished. The following are all examples of valid, distinct
+variable names:
+
+  a       tooBig?     a1B2c3%!?
+  A       %j          numberOfPoints
+  beta6   %J          numberofpoints
+
+The ":=" operator is the immediate assignment operator. Use it to 
+associate a value with a variable. The syntax for immediate assignment
+for a single variable is:
+
+   variable := expression
+
+The value returned by an immediate assignment is the value of expression.
+
+  a := 1
+    1             
+           Type: PositiveInteger
+
+The right-hand side of the expression is evaluated, yielding 1. The value
+is then assigned to a.
+
+  b := a
+    1             
+           Type: PositiveInteger
+
+The right-hand side of the expression is evaluated, yieldig 1. This value
+is then assigned to b. Thus a and b both have the value 1 after the sequence
+of assignments.
+
+  a := 2
+    2
+           Type: PositiveInteger
+
+What is the value of b if a is assigned the value 2?
+
+  b
+    1
+           Type: PositiveInteger
+
+The value of b is left unchanged.
+
+This is what we mean when we say this kind of assignment is immediate.
+The variable b has no dependency on a after the initial assignment. This
+is the usual notion of assignment in programming languages such as C,
+Pascal, and Fortran.
+
+====================================================================
+Delayed Assignment
+====================================================================
+
+Axiom provides delayed assignment with "==". This implements a delayed
+evaluation of the right-hand side and dependency checking. The syntax for
+delayed assignment is
+
+   variable == expression
+
+The value returned by a delayed assignment is the unique value of Void.
+
+  a == 1
+           Type: Void
+
+  b == a
+           Type: Void
+
+Using a and b as above, these are the corresponding delayed assignments.
+
+  a
+   Compiling body of rule a to compute value of type PositiveInteger
+   1
+           Type: PositiveInteger
+
+The right-hand side of each delayed assignment is left unevaluated until
+the variables on the left-hand sides are evaluated. 
+
+  b
+   Compiling body of rule b to compute value of type PositiveInteger
+   1
+           Type: PositiveInteger
+
+This gives the same results as before. But if we change a to 2
+
+  a == 2
+   Compiled code for a has been cleared.
+   Compiled code for b has been cleared.
+   1 old definition(s) deleted for function or rule a
+           Type: Void
+
+Then a evaluates to 2, as expected
+
+  a
+   Compiling body of rule a to compute value of type PositiveInteger
+   2
+           Type: PositiveInteger
+
+but the value of b reflects the change to a
+
+  b
+   Compiling body of rule b to compute value of type PositiveInteger
+   2
+           Type: PositiveInteger
+
+====================================================================
+Multiple Immediate Assignments
+====================================================================
+
+It is possible to set several variables at the same time by using a
+tuple of variables and a tuple of expressions. A tuple is a collection
+of things separated by commas, often surrounded by parentheses. The
+syntax for multiple immediate assignment is
+
+ ( var1, var2, ..., varN ) := ( expr1, expr2, ..., exprN )
+
+The value returned by an immediate assignment is the value of exprN.
+
+ ( x, y ) := ( 1, 2 )
+   2
+           Type: PositiveInteger
+
+This sets x to 1 and y to 2. Multiple immediate assignments are parallel
+in the sense that the expressions on the right are all evaluated before
+any assignments on the left are made. However, the order of evaluation
+of these expressions is undefined.
+
+ ( x, y ) := ( y, x )
+   1
+           Type: PositiveInteger
+
+  x
+   2
+           Type: PositiveInteger
+
+The variable x now has the previous value of y.
+
+  y
+   1
+           Type: PositiveInteger
+
+The variable y now has the previous value of x.
+
+There is no syntactic form for multiple delayed assignments. 
+
+@
+
+\section{command boot}
 <<boot>>=
 ====================================================================
 A.3.  )boot
@@ -115,7 +271,95 @@ o )system
  
 @
 
-\section{cd}
+\section{syntax blocks}
+<<blocks>>=
+====================================================================
+Blocks
+====================================================================
+
+A block is a sequence of expressions evaluated in the order that they
+appear, except as modified by control expressions such as leave, return,
+iterate, and if-then-else constructions. The value of a block is the
+value of the expression last evaluated in the block.
+
+To leave a block early, use "=>". For example, 
+
+    i < 0 => x
+
+The expression before the "=>" must evaluate to true or false. The
+expression following the "=>" is the return value of the block.
+
+A block can be constructed in two ways:
+
+  1. the expressions can be separated by semicolons and the resulting
+     expression surrounded by parentheses, and
+  2. the expressions can be written on succeeding lines with each line
+     indented the same number of spaces (which must be greater than zero).
+     A block entered in this form is called a pile
+
+Only the first form is available if you are entering expressions directly
+to Axiom. Both forms are available in .input files. The syntax for a simple
+block of expressions entered interactively is
+
+  ( expression1 ; expression2 ; ... ; expressionN )
+
+The value returned by a block is the value of an "=>" expression, or
+expressionN if no "=>" is encountered.
+
+In .input files, blocks can also be written in piles. The examples
+given here are assumed to come from .input files.
+
+  a := 
+    i := gcd(234,672)
+    i := 2*i**5 - i + 1
+    1 / i
+
+      1
+    -----
+    23323
+              Type: Fraction Integer
+
+In this example, we assign a rational number to a using a block consisting
+of three expressions. This block is written as a pile. Each expression in
+the pile has the same indentation, in this case two spaces to the right of
+the first line.
+
+  a := ( i := gcd(234,672); i := 2*i**5 - i + 1; 1 / i )
+
+      1
+    -----
+    23323
+              Type: Fraction Integer
+
+Here is the same block written on one line. This is how you are required
+to enter it at the input prompt.
+
+  ( a := 1; b := 2; c := 3; [a,b,c] )
+    [1,2,3]
+              Type: List PositiveInteger
+
+AAxiom gives you two ways of writing a block and the preferred way in
+an .input file is to use a pile. Roughly speaking, a pile is a block
+whose consituent expressions are indented the same amount. You begin a
+pile by starting a new line for the first expression, indenting it to
+the right of the previous line. You then enter the second expression on
+a new line, vertically aligning it with the first line. And so on. If
+you need to enter an inner pile, further indent its lines to the right
+of the outer pile. Axiom knows where a pile ends. It ends when a subsequent
+line is indented to the left of the pile or the end of the file.
+
+Also See: 
+o )help if
+o )help repeat
+o )help while
+o )help for
+o )help suchthat
+o )help parallel
+o )help lists
+
+@
+
+\section{command cd}
 <<cd>>=
 ====================================================================
 A.4.  )cd
@@ -152,7 +396,7 @@ o )spool
  
 @
 
-\section{clear}
+\section{command clear}
 <<clear>>=
 ====================================================================
 A.6.  )clear
@@ -236,7 +480,56 @@ o )undo
  
 @
 
-\section{close}
+\section{system clef}
+<<clef>>=
+
+Entering printable keys generally inserts new text into the buffer (unless
+in overwrite mode, see below).  Other special keys can be used to modify
+the text in the buffer.  In the description of the keys below, ^n means
+Control-n, or holding the CONTROL key down while pressing "n".  Errors
+will ring the terminal bell.
+
+^A/^E  : Move cursor to beginning/end of the line.
+^F/^B   : Move cursor forward/backward one character.
+^D     : Delete the character under the cursor.
+^H, DEL : Delete the character to the left of the cursor.
+^K     : Kill from the cursor to the end of line.
+^L     : Redraw current line.
+^O     : Toggle overwrite/insert mode. Initially in insert mode. Text
+         added in overwrite mode (including yanks) overwrite
+         existing text, while insert mode does not overwrite.
+^P/^N   : Move to previous/next item on history list.
+^R/^S   : Perform incremental reverse/forward search for string on
+         the history list.  Typing normal characters adds to the current
+         search string and searches for a match. Typing ^R/^S marks
+         the start of a new search, and moves on to the next match.
+         Typing ^H or DEL deletes the last character from the search 
+         string, and searches from the starting location of the last search.  
+         Therefore, repeated DEL's appear to unwind to the match nearest 
+         the point at which the last ^R or ^S was typed.  If DEL is 
+         repeated until the search string is empty the search location 
+         begins from the start of the history list.  Typing ESC or 
+         any other editing character accepts the current match and 
+         loads it into the buffer, terminating the search.
+^T     : Toggle the characters under and to the left of the cursor.
+^Y     : Yank previously killed text back at current location.  Note that
+         this will overwrite or insert, depending on the current mode.
+^U      : Show help (this text).
+TAB    : Perform command completion based on word to the left of the cursor. 
+          Words are deemed to contain only the alphanumeric and the % ! ? _  
+          characters.
+NL, CR  : returns current buffer to the program.
+
+DOS and ANSI terminal arrow key sequences are recognized, and act like:
+
+  up    : same as ^P
+  down  : same as ^N
+  left  : same as ^B
+  right : same as ^F
+
+@ 
+
+\section{command close}
 <<close>>=
 ====================================================================
 A.5.  )close
@@ -278,7 +571,78 @@ o )pquit
  
 @
 
-\section{compile}
+\section{syntax collection}
+<<collection>>=
+====================================================================
+Collection -- Creating Lists and Streams with Iterators
+====================================================================
+
+All of the loop expressions which do not use the repeat leave or
+iterate words can be used to create lists and streams. For example:
+
+This creates a simple list of the integers from 1 to 10:
+
+  list := [i for i in 1..10]
+   [1,2,3,4,5,6,7,8,9,10]
+                      Type: List PositiveInteger
+
+Create a stream of the integers greater than or equal to 1:
+
+  stream := [i for i in 1..]
+   [1,2,3,4,5,6,7,...]
+                      Type: Stream PositiveInteger
+
+This is a list of the prime numbers between 1 and 10, inclusive:
+
+  [i for i in 1..10 | prime? i]
+   [2,3,5,7]
+                      Type: List PositiveInteger
+
+This is a stream of the prime integers greater than or equal to 1:
+  
+  [i for i in 1.. | prime? i]
+   [2,3,5,7,11,13,17,...]
+                      Type: Stream PositiveInteger
+
+This is a list of the integers between 1 and 10, inclusive, whose
+squares are less than 700:
+
+  [i for i in 1..10 while i*i < 700]
+   [1,2,3,4,5,6,7,8,9,10]
+                      Type: List PositiveInteger
+
+This is a stream of the integers greater than or equal to 1 whose
+squares are less than 700:
+
+  [i for i in 1.. while i*i < 700]
+   [1,2,3,4,5,6,7,...]
+                      Type: Stream PositiveInteger
+
+The general syntax of a collection is
+
+  [ collectExpression iterator1 iterator2 ... iteratorN ]
+
+where each iterator is either a for or a while clause. The loop 
+terminates immedidately when the end test of any iterator succeeds
+or when a return expression is evaluated in collectExpression. The
+value returned by the collection is either a list or a stream of
+elements, one for each iteration of the collectExpression.
+
+Be careful when you use while to create a stream. By default Axiom
+tries to compute and display the first ten elements of a stream. If
+the while condition is not satisfied quickly, Axiom can spend a long
+(potentially infinite) time trying to compute the elements. Use
+
+  )set streams calculate 
+
+to change the defaults to something else. This also affects the number
+of terms computed and displayed for power series. For the purposes of
+these examples we have use this system command to display fewer than
+ten terms.
+
+@
+
+\section{command compile}
 <<compile>>=
 ====================================================================
 A.7.  )compile
@@ -533,7 +897,8 @@ o )edit
 o )library
 
 @ 
-\section{display}
+
+\section{command display}
 <<display>>=
 ====================================================================
 A.8.  )display
@@ -608,7 +973,8 @@ o )show
 o )what
  
 @ 
-\section{edit}
+
+\section{command edit}
 <<edit>>=
 ====================================================================
 A.9.  )edit
@@ -656,7 +1022,8 @@ o )read
  
 
 @ 
-\section{fin}
+
+\section{command fin}
 <<fin>>=
 ====================================================================
 A.10.  )fin
@@ -680,7 +1047,213 @@ o )quit
  
 
 @ 
-\section{frame}
+
+\section{syntax for}
+<<for>>=
+====================================================================
+for loops
+====================================================================
+
+Axiom provide the for and in keywords in repeat loops, allowing you
+to integrate across all elements of a list, or to have a variable take
+on integral values from a lower bound to an upper bound. We shall refer
+to these modifying clauses of repeat loops as for clauses. These clauses
+can be present in addition to while clauses (See )help while). As with
+all other types of repeat loops, leave (see )help leave) can be used to 
+prematurely terminate evaluation of the loop.
+
+The syntax for a simple loop using for is
+
+  for iterator repeat loopbody
+
+The iterator has several forms. Each form has an end test which is
+evaluted before loopbody is evaluated. A for loop terminates immediately
+when the end test succeeds (evaluates to true) or when a leave or return
+expression is evaluated in loopbody. The value returned by the loop is 
+the unique value of Void.
+
+====================================================================
+for i in n..m repeat
+====================================================================
+
+If for is followed by a variable name, the in keyword and then an integer
+segment of the form n..m, the end test for this loop is the predicate 
+i > m. The body of the loop is evaluated m-n+1 times if this number is
+greater than 0. If this number is less than or equal to 0, the loop body
+is not evaluated at all.
+
+The variable i has the value n, n+1, ..., m for successive iterations
+of the loop body. The loop variable is a local variable within the loop
+body. Its value is not available outside the loop body and its value and
+type within the loop body completely mask any outer definition of a
+variable with the same name.
+
+  for i in 10..12 repeat output(i**3)
+   1000
+   1331
+   1728
+                      Type: Void
+
+The loop prints the values of 10^3, 11^3, and 12^3.
+
+  a := [1,2,3]
+   [1,2,3]
+                      Type: List PositiveInteger
+
+  for i in 1..#a repeat output(a.i)
+   1
+   2
+   3
+                      Type: Void
+
+Iterate across this list using "." to access the elements of a list
+and the # operation to count its elements.
+
+This type of iteration is applicable to anything that uses ".". You 
+can also use it with functions that use indices to extract elements.
+
+   m := matrix [[1,2],[4,3],[9,0]]
+    +-    -+
+    | 1  2 |
+    | 4  3 |
+    | 9  0 |
+    +-    -+
+                      Type: Matrix Integer
+
+Define m to be a matrix.
+
+   for i in 1..nrows(m) repeat output row(m.i)
+    [1,2]
+    [4,3]
+    [9,0]
+                      Type: Void
+
+Display the rows of m.
+
+You can iterate with for-loops.
+
+   for i in 1..5 repeat
+     if odd?(i) then iterate
+     output(i)
+    2
+    4
+                      Type: Void
+
+Display the even integers in a segment.
+
+====================================================================
+for i in n..m by s repeat
+====================================================================
+
+By default, the difference between values taken on by a variable in
+loops such as 
+
+  for i in n..m repeat ...
+
+is 1. It is possible to supply another, possibly negative, step value
+by using the by keyword along with for and in. Like the upper and lower
+bounds, the step value following the by keyword must be an integer. Note
+that the loop
+
+  for i in 1..2 by 0 repeat output(i)
+
+will not terminate by itself, as the step value does not change the
+index from its initial value of 1.
+
+  for i in 1..5 by 2 repeat output(i)
+   1
+   3
+   5
+                      Type: Void
+
+This expression displays the odd integers between two bounds.
+
+  for i in 5..1 by -2 repeat output(i)
+   5
+   3
+   1
+                      Type: Void
+
+Use this to display the numbers in reverse order.
+
+====================================================================
+for i in n.. repeat
+====================================================================
+
+If the value after the ".." is omitted, the loop has no end test. A
+potentially infinite loop is thus created. The variable is given the
+successive values n, n+1, n+2, ... and the loop is terminated only
+if a leave or return expression is evaluated in the loop body. However,
+you may also add some other modifying clause on the repeat, for example,
+a while clause, to stop the loop.
+
+  for i in 15.. while not prime?(i) repeat output(i)
+   15
+   16
+                      Type: Void
+
+This loop displays the integers greater than or equal to 15 and less
+than the first prime number greater than 15.
+
+====================================================================
+for x in l repeat
+====================================================================
+
+Another variant of the for loop has the form:
+
+  for x in list repeat loopbody
+
+This form is used when you want to iterate directly over the elements
+of a list. In this form of the for loop, the variable x takes on the
+value of each successive element in l. The end test is most simply
+stated in English: "are there no more x in l?"
+
+  l := [0, -5, 3]
+   [0, -5, 3]
+                      Type: List Integer
+
+  for x in l repeat output(x)
+   0
+   -5
+   3
+                      Type: Void
+
+This displays all of the elements of the list l, one per line.
+
+Since the list constructing expression 
+
+  expand [n..m]
+
+creates the list
+
+  [n, n+1, ..., m]
+
+you might be tempted to think that the loops
+
+  for i in n..m repeat output(i)
+
+and
+
+  for x in expand [n..m] repeat output(x)
+
+are equivalent. The second form first creates the expanded list
+(no matter how large it might be) and then does the iteration. The
+first form potentially runs in much less space, as the index variable
+i is simply incremented once per loop and the list is not actually
+created. Using the first form is much more efficient.
+
+Of course, sometimes you really want to iterate across a specific list.
+This displays each of the factors of 2400000:
+
+  for f in factors(factor(2400000)) repeat output(f)
+   [factor= 2, exponent= 8]
+   [factor= 3, exponent= 1]
+   [factor= 5, exponent= 5]
+                      Type: Void
+
+@
+
+\section{command frame}
 <<frame>>=
 ====================================================================
 A.11.  )frame
@@ -775,7 +1348,8 @@ o )history
 o )set
  
 @ 
-\section{help}
+
+\section{command help}
 <<help>>=
 ====================================================================
 A.12.  )help
@@ -787,6 +1361,7 @@ Command Syntax:
  
   - )help
   - )help commandName
+  - )help syntax
  
 Command Description: 
  
@@ -800,6 +1375,12 @@ of a system command to display information about it. For 
example,
 )help clear
  
 will display the description of the )clear system command.
+
+The command 
+
+)help syntax
+
+will give further information about the Axiom language syntax.
  
 All this material is available in the AXIOM User Guide and in HyperDoc. In
 HyperDoc, choose the Commands item from the Reference menu.
@@ -885,9 +1466,23 @@ only on and off are acceptable words for following boot. 
We also sometimes
 use ``...'' to indicate that additional arguments or options of the listed
 form are allowed. Finally, in the syntax descriptions we may also list the
 syntax of related commands.
- 
+
+====================================================================
+Other help topics
+====================================================================
+Available help topics are: 
+
+abbreviations assignment boot       blocks     cd         clear      
+clef          close      collection compile    display    edit       
+fin           for        frame      help       history    if         
+iterate       leave      library    lisp       load       ltrace     
+parallel      pquit      quit       read       repeat     savesystem 
+set           show       spool      suchthat   synonym    system     
+syntax        trace      undo       what       while
+
 @ 
-\section{history}
+
+\section{command history}
 <<history>>=
 ====================================================================
 A.13.  )history
@@ -1028,15 +1623,210 @@ o )undo
  
 @ 
 
-\section{language}
-<<language>>=
-The Axiom Interactive Language has the following features.
-More information is available by typing
-  )help feature
+\section{syntax if}
+<<if>>=
+====================================================================
+If-then-else
+====================================================================
+
+Like many other programming languages, Axiom uses the three keywords
+if, then, and else to form conditional expressions. The else part of
+the conditional is optional. The expression between the if and then
+keywords is a predicate: an expression that evaluates to or is
+convertible to either true or false, that is, a Boolean.
+
+The syntax for conditional expressions is
+
+   if predicate then expression1 else expression2
+
+where the "else expression2" part is optional. The value returned from
+a conditional expression is expression1 if the predicate evaluates to
+true and expression2 otherwise. If no else clause is given, the value
+is always the unique value of Void.
+
+An if-then-else expression always returns a value. If the else clause
+is missing then the entire expression returns the unique value of Void.
+If both clauses are present, the type of the value returned by if is
+obtained by resolving the types of the values of the two clauses.
+
+The predicate must evaluate to, or be convertible to, an object of type
+Boolean: true or false. By default, the equal sign "=" creates an equation.
+
+   x + 1 = y
+    x + 1 = y
+                Type: Equation Polynomial Integer
+
+This is an equation, not a boolean condition. In particular, it is
+an object of type Equation Polynomial Integer.
+
+However, for predicates in if expressions, Axiom places a default 
+target type of Boolean on the predicate and equality testing is performed.
+Thus you need not qualify the "=" in any way. In other contexts you may
+need to tell Axiom that you want to test for equality rather than create
+an equation. In these cases, use "@" and a target type of Boolean.
+
+The compound symbol meaning "not equal" in Axiom is "~=". This can be
+used directly without a package call or a target specification. The
+expression "a ~= b" is directly translated to "not(a = b)".
+
+Many other functions have return values of type Boolean. These include
+<, <=, >, >=, ~=, and member?. By convention, operations with names
+ending in "?" return Boolean values.
+
+The usual rules for piles are suspended for conditional expressions. In
+.input files, the then and else keywords can begin in the same column
+as the corresponding if by may also appear to the right. Each of the
+following styles of writing if-then-else expressions is acceptable:
+
+  if i>0 then output("positive") else output("nonpositive")
+
+  if i>0 then output("positive")
+    else output("nonpositive")
+
+  if i>0 then output("positive")
+  else output("nonpositive")
+
+  if i>0 
+  then output("positive")
+  else output("nonpositive")
+
+  if i>0 
+    then output("positive")
+    else output("nonpositive")
+
+A block can follow the then or else keywords. In the following two 
+assignments to a, the then and else clauses each are followed by two
+line piles. The value returned in each is the value of the second line.
+
+  a :=
+    if i > 0 then
+      j := sin(i * pi())
+      exp(j + 1/j)
+    else
+      j := cos(i * 0.5 * pi())
+      log(abs(j)**5 + i)
+
+
+  a :=
+    if i > 0 
+      then
+        j := sin(i * pi())
+        exp(j + 1/j)
+      else
+        j := cos(i * 0.5 * pi())
+        log(abs(j)**5 + i)
+
+These are both equivalent to the following:
+
+  a := 
+    if i > 0 then (j := sin(i * pi()); exp(j + 1/j))
+    else (j := cos(i * 0.5 * pi()); log(abs(j)**5 + i))
 
 @
 
-\section{library}
+\section{syntax iterate}
+<<iterate>>=
+====================================================================
+iterate in loops
+====================================================================
+
+Axiom provides an iterate expression that skips over the remainder
+of a loop body and starts the next loop execution. We first initialize
+a counter.
+
+  i := 0
+   0
+                      Type: NonNegativeInteger
+
+Display the even integers from 2 to 5:
+
+  repeat
+    i := i + 1
+    if i > 5 then leave
+    if odd?(i) then iterate
+    output(i)
+   2
+   4
+                      Type: Void
+
+@
+
+\section{syntax leave}
+<<leave>>=
+====================================================================
+leave in loops
+====================================================================
+
+The leave keyword is often more useful in terminating a loop. A
+leave causes control to transfer to the expression immediately following
+the loop. As loops always return the unique value of Void, you cannot
+return a value with leave. That is, leave takes no argument.
+
+  f() ==
+    i := 1
+    repeat
+      if factorial(i) > 1000 then leave
+      i := i + 1
+    i
+                      Type: Void
+
+This example is a modification of the last example in the previous
+section. Instead of using return we'll use leave.
+
+  f()
+   7
+                      Type: PositiveInteger
+
+The loop terminates when factorial(i) gets big enough. The last line
+of the function evaluates to the corresponding "good" value of i
+and the function terminates, returning that value.
+
+You can only use leave to terminate the evaluation of one loop. Lets
+consider a loop within a loop, that is, a loop with a nested loop. 
+First, we initialize two counter variables.
+
+  (i,j) := (1,1)
+   1
+                      Type: PositiveInteger
+
+  repeat
+    repeat
+      if (i + j) > 10 then leave
+      j := j + 1
+    if (i + j) > 10 then leave
+    i := i + 1
+                      Type: Void
+
+Nested loops must have multiple leave expressions at the appropriate
+nesting level. How would you rewrite this so (i + j) > 10 is only
+evaluated once?
+
+====================================================================
+leave vs => in loop bodies
+====================================================================
+
+Compare the following two loops:
+
+  i := 1                      i := 1
+  repeat                      repeat
+    i := i + 1                  i := i + 1
+    i > 3 => i                  if i > 3 then leave
+    output(i)                   output(i)
+
+In the example on the left, the values 2 and 3 for i are displayed but
+then the "=>" does not allow control to reach the call to output again.
+The loop will not terminate until you run out of space or interrupt the
+execution. The variable i will continue to be incremented because the
+"=>" only means to leave the block, not the loop.
+
+In the example on the right, upon reaching 4, the leave will be executed,
+and both the block and the loop will terminate. This is one of the reasons
+why both "=>" and leave are provided. Using a while clase with the "=>"
+lets you simulate the action of leave.
+
+@
+
+\section{command library}
 <<library>>=
 ====================================================================
 A.14.  )library
@@ -1094,7 +1884,8 @@ o )frame
 o )set
  
 @ 
-\section{lisp}
+
+\section{command lisp}
 <<lisp>>=
 ====================================================================
 A.15.  )lisp
@@ -1123,7 +1914,8 @@ o )boot
 o )fin
  
 @ 
-\section{load}
+
+\section{command load}
 <<load>>=
 ====================================================================
 A.16.  )load
@@ -1136,7 +1928,8 @@ Command Description:
 This command is obsolete. Use )library instead.
  
 @ 
-\section{ltrace}
+
+\section{command ltrace}
 <<ltrace>>=
 ====================================================================
 A.17.  )ltrace
@@ -1159,55 +1952,115 @@ o )lisp
 o )trace
  
 @ 
-\section{nclef}
-<<nclef>>=
 
-Entering printable keys generally inserts new text into the buffer (unless
-in overwrite mode, see below).  Other special keys can be used to modify
-the text in the buffer.  In the description of the keys below, ^n means
-Control-n, or holding the CONTROL key down while pressing "n".  Errors
-will ring the terminal bell.
 
-^A/^E  : Move cursor to beginning/end of the line.
-^F/^B   : Move cursor forward/backward one character.
-^D     : Delete the character under the cursor.
-^H, DEL : Delete the character to the left of the cursor.
-^K     : Kill from the cursor to the end of line.
-^L     : Redraw current line.
-^O     : Toggle overwrite/insert mode. Initially in insert mode. Text
-         added in overwrite mode (including yanks) overwrite
-         existing text, while insert mode does not overwrite.
-^P/^N   : Move to previous/next item on history list.
-^R/^S   : Perform incremental reverse/forward search for string on
-         the history list.  Typing normal characters adds to the current
-         search string and searches for a match. Typing ^R/^S marks
-         the start of a new search, and moves on to the next match.
-         Typing ^H or DEL deletes the last character from the search 
-         string, and searches from the starting location of the last search.  
-         Therefore, repeated DEL's appear to unwind to the match nearest 
-         the point at which the last ^R or ^S was typed.  If DEL is 
-         repeated until the search string is empty the search location 
-         begins from the start of the history list.  Typing ESC or 
-         any other editing character accepts the current match and 
-         loads it into the buffer, terminating the search.
-^T     : Toggle the characters under and to the left of the cursor.
-^Y     : Yank previously killed text back at current location.  Note that
-         this will overwrite or insert, depending on the current mode.
-^U      : Show help (this text).
-TAB    : Perform command completion based on word to the left of the cursor. 
-          Words are deemed to contain only the alphanumeric and the % ! ? _  
-          characters.
-NL, CR  : returns current buffer to the program.
+\section{syntax parallel}
+<<parallel>>=
+====================================================================
+parallel iteration
+====================================================================
 
-DOS and ANSI terminal arrow key sequences are recognized, and act like:
+Sometimes you want to iterate across two lists in parallel, or perhaps
+you want to traverse a list while incrementing a variable.
 
-  up    : same as ^P
-  down  : same as ^N
-  left  : same as ^B
-  right : same as ^F
+The general syntax of a repeat loop is
 
-@ 
-\section{pquit}
+ iterator1, iterator2, ..., iteratorN repeat loopbody
+
+where each iterator is either a for or a while clause. The loop 
+terminates immediately when the end test of any iterator succeeds or 
+when a leave or return expression is evaluated in loopbody. The value
+returned by the loop is the unique value of Void.
+
+  l := [1,3,5,7]
+   [1,3,5,7]
+                      Type: List PositiveInteger
+
+  m := [100,200]
+   [100,200]
+                      Type: List PositiveInteger
+
+  sum := 0
+   0
+                      Type: NonNegativeInteger
+
+Here we write a loop to iterate across two lists, computing the sum
+of the pairwise product of the elements:
+
+  for x in l for y in m repeat
+    sum := sum + x*y
+                      Type: Void
+
+The last two elements of l are not used in the calculation because
+m has two fewer elements than l.
+
+  sum
+   700
+                      Type: NonNegativeInteger
+
+This is the "dot product".
+
+Next we write a loop to compute the sum of the products of the loop
+elements with their positions in the loop.
+
+  l := [2,3,5,7,11,13,17,19,23,29,31,37]
+   [2,3,5,7,11,13,17,19,23,29,31,37]
+                      Type: List PositiveInteger
+
+  sum := 0
+   0
+                      Type: NonNegativeInteger
+
+  for i in 0.. for x in l repeat sum := i * x
+                      Type: Void
+
+Here looping stops when the list l is exhaused, even though the
+for i in 0.. specifies no terminating condition.
+
+  sum 
+   407
+                      Type: NonNegativeInteger
+
+When "|" is used to qualify any of the for clauses in a parallel 
+iteration, the variables in the predicates can be from an outer
+scope or from a for clause in or to the left of the modified clause.
+
+This is correct:
+ 
+  for i in 1..10 repeat
+    for j in 200..300 | ood? (i+j) repeat
+      output [i,j]
+
+But this is not correct. The variable j has not been defined outside
+the inner loop:
+
+  for i in 1..01 | odd? (i+j) repeat -- wrong, j not defined
+    for j in 200..300 repeat
+      output [i,j]
+
+It is possible to mix several of repeat modifying clauses on a loop:
+
+  for i in 1..10
+    for j in 151..160 | odd? j
+      while i + j < 160 repeat
+        output [i,j]
+   [1,151]
+   [3,153]
+                      Type: Void
+
+Here are useful rules for composing loop expressions:
+
+ 1. while predicates can only refer to variables that are global (or
+    in an outer scope) or that are defined in for clauses to the left
+    of the predicate.
+ 2. A "such that" predicate (somthing following "|") must directly
+    follow a for clause and can only refer to variables that are
+    global (or in an outer scope) or defined in the modified for clause
+    or any for clause to the left.
+
+@
+
+\section{command pquit}
 <<pquit>>=
 ====================================================================
 A.18.  )pquit
@@ -1254,7 +2107,8 @@ o )quit
 o )system
  
 @ 
-\section{quit}
+
+\section{command quit}
 <<quit>>=
 ====================================================================
 A.19.  )quit
@@ -1298,7 +2152,8 @@ o )pquit
 o )system
  
 @ 
-\section{read}
+
+\section{command read}
 <<read>>=
 ====================================================================
 A.20.  )read
@@ -1337,19 +2192,199 @@ o )edit
 o )history
  
 @ 
-\section{savesystem}
-<<savesystem>>=
-AXIOM Help Information. Section numbers refer to the book 
-AXIOM: The System for Scientific Computation. 
+
+\section{syntax repeat}
+<<repeat>>=
+====================================================================
+Repeat Loops
+====================================================================
+
+A loop is an expression that contains another expression, called the loop
+body, which is to be evaluated zero or more times. All loops contain the
+repeat keyword and return the unique value of Void. Loops can contain
+inner loops to any depth.
+
+The most basic loop is of the form
  
+  repeat loopbody
+
+Unless loopbody contains a leave or return expression, the loop repeats
+foreer. The value returned by the loop is the unique value of Void.
+
+Axiom tries to determine completely the type of every object in a loop
+and then to translate the loop body to Lisp or even to machine code. This
+translation is called compilation.
+
+If Axiom decides that it cannot compile the loop, it issues a message
+stating the problem and then the following message:
+
+  We will attemp to step through and interpret the code
+
+It is still possible that Axiom can evalute the loop but in interpret-code
+mode.
+
+====================================================================
+Return in Loops
+====================================================================
+
+A return expression is used to exit a function with a particular value.
+In particular, if a return is in a loop within the function, the loop
+is terminated whenever the return is evaluated. 
+
+  f() ==
+    i := 1
+    repeat
+      if factorial(i) > 1000 then return i
+      i := i + 1
+                      Type: Void
+
+  f()
+                      Type: Void
+
+When factorial(i) is big enough, control passes from inside the loop
+all the way outside the function, returning the value of i (so we think).
+What went wrong? Isn't it obvious that this function should return an
+integer? Well, Axiom makes no attempt to analyze the structure of a
+loop to determine if it always returns a value because, in general, this
+is impossible. So Axiom has this simple rule: the type of the function is
+determined by the type of its body, in this case a block. The normal value
+of a block is the value of its last expression, in this case, a loop. And
+the value of every loop is the unique value of Void. So the return type
+of f is Void.
+
+There are two ways to fix this. The best way is for you to tell Axiom
+what the return type of f is. You do this by giving f a declaration
+
+   f:() -> Integer
+
+prior to calling for its value. This tells Axiom "trust me -- an integer
+is returned". Another way is to add a dummy expression as follows.
+
+  f() ==
+    i := 1
+    repeat
+      if factorial(i) > 1000 then return i
+      i := i + 1
+    0
+                      Type: Void
+
+Note that the dummy expression will never be evaluated but it is the
+last expression in the function and will determine the return type.
+
+  f()
+   7
+                      Type: PositiveInteger
+
+====================================================================
+leave in loops
+====================================================================
+
+The leave keyword is often more useful in terminating a loop. A
+leave causes control to transfer to the expression immediately following
+the loop. As loops always return the unique value of Void, you cannot
+return a value with leave. That is, leave takes no argument.
+
+  f() ==
+    i := 1
+    repeat
+      if factorial(i) > 1000 then leave
+      i := i + 1
+    i
+                      Type: Void
+
+This example is a modification of the last example in the previous
+section. Instead of using return we'll use leave.
+
+  f()
+   7
+                      Type: PositiveInteger
+
+The loop terminates when factorial(i) gets big enough. The last line
+of the function evaluates to the corresponding "good" value of i
+and the function terminates, returning that value.
+
+You can only use leave to terminate the evaluation of one loop. Lets
+consider a loop within a loop, that is, a loop with a nested loop. 
+First, we initialize two counter variables.
+
+  (i,j) := (1,1)
+   1
+                      Type: PositiveInteger
+
+  repeat
+    repeat
+      if (i + j) > 10 then leave
+      j := j + 1
+    if (i + j) > 10 then leave
+    i := i + 1
+                      Type: Void
+
+Nested loops must have multiple leave expressions at the appropriate
+nesting level. How would you rewrite this so (i + j) > 10 is only
+evaluated once?
+
+====================================================================
+leave vs => in loop bodies
+====================================================================
+
+Compare the following two loops:
+
+  i := 1                      i := 1
+  repeat                      repeat
+    i := i + 1                  i := i + 1
+    i > 3 => i                  if i > 3 then leave
+    output(i)                   output(i)
+
+In the example on the left, the values 2 and 3 for i are displayed but
+then the "=>" does not allow control to reach the call to output again.
+The loop will not terminate until you run out of space or interrupt the
+execution. The variable i will continue to be incremented because the
+"=>" only means to leave the block, not the loop.
+
+In the example on the right, upon reaching 4, the leave will be executed,
+and both the block and the loop will terminate. This is one of the reasons
+why both "=>" and leave are provided. Using a while clase with the "=>"
+lets you simulate the action of leave.
+
+====================================================================
+iterate in loops
+====================================================================
+
+Axiom provides an iterate expression that skips over the remainder
+of a loop body and starts the next loop execution. We first initialize
+a counter.
+
+  i := 0
+   0
+                      Type: NonNegativeInteger
+
+Display the even integers from 2 to 5:
+
+  repeat
+    i := i + 1
+    if i > 5 then leave
+    if odd?(i) then iterate
+    output(i)
+   2
+   4
+                      Type: Void
+
+Also See: 
+o )help blocks
+o )help if
+o )help while
+o )help for
+o )help suchthat
+o )help parallel
+o )help lists
+
+@
+\section{command savesystem}
+<<savesystem>>=
 ====================================================================
 A.8.  )savesystem
 ====================================================================
  
- 
- 
- 
- 
 User Level Required:  interpreter
  
  
@@ -1377,7 +2412,8 @@ There is currently a restriction that only systems 
started with the
 command "AXIOMsys" may be saved.
 
 @ 
-\section{set}
+
+\section{command set}
 <<set>>=
 ====================================================================
 A.21.  )set
@@ -1433,7 +2469,8 @@ Also See:
 o )quit
  
 @ 
-\section{show}
+
+\section{command show}
 <<show>>=
 ====================================================================
 A.22.  )show
@@ -1485,7 +2522,8 @@ o )set
 o )what
  
 @ 
-\section{spool}
+
+\section{command spool}
 <<spool>>=
 ====================================================================
 A.23.  )spool
@@ -1518,7 +2556,50 @@ Also See:
 o )cd
  
 @ 
-\section{synonym}
+
+\section{syntax suchthat}
+<<suchthat>>=
+====================================================================
+Such that predicates
+====================================================================
+
+A for loop can be followed by a "|" and then a predicate. The predicate
+qualifies the use of the values from the iterator that follows the for.
+Think of the vertical bar "|" as the phrase "such that".
+
+  for n in 0..4 | odd? n repeat output n
+   1
+   3
+                      Type: Void
+
+This loop expression prints out the integers n in the given segment
+such that n is odd.
+
+A for loop can also be written
+
+  for iterator | predicate repeat loopbody
+
+which is equivalent to:
+
+  for iterator repeat if predicate then loopbody else iterate
+
+The predicate need not refer only to the variable in the for clause.
+Any variable in an outer scope can be part of the predicate.
+
+  for i in 1..50 repeat
+    for j in 1..50 | factorial(i+j) < 25 repeat
+      output [i,j]
+   [1,1]
+   [1,2]
+   [1,3]
+   [2,1]
+   [2,2]
+   [3,1]
+                      Type: Void
+
+@
+
+\section{command synonym}
 <<synonym>>=
 ====================================================================
 A.24.  )synonym
@@ -1566,7 +2647,8 @@ o )set
 o )what
  
 @ 
-\section{system}
+
+\section{command system}
 <<system>>=
 ====================================================================
 A.25.  )system
@@ -1603,7 +2685,33 @@ o )pquit
 o )quit
  
 @ 
-\section{trace}
+
+\section{syntax syntax}
+<<syntax>>=
+
+The Axiom Interactive Language has the following features documented here.
+
+More information is available by typing
+
+  )help feature
+
+where feature is one of:
+
+  assignment -- Immediate and delayed assignments
+  blocks     -- Blocks of expressions
+  collection -- creating lists with iterators
+  for        -- for loops
+  if         -- If-then-else statements
+  iterate    -- using iterate in loops
+  leave      -- using leave in loops
+  parallel   -- parallel iterations
+  repeat     -- repeat loops
+  suchthat   -- suchthat predicates
+  while      -- while loops
+
+@
+
+\section{command trace}
 <<trace>>=
 ====================================================================
 A.26.  )trace
@@ -1823,7 +2931,8 @@ o )lisp
 o )ltrace
  
 @ 
-\section{undo}
+
+\section{command undo}
 <<undo>>=
 ====================================================================
 A.27.  )undo
@@ -1884,7 +2993,8 @@ The command )history )write will eliminate the ``undone'' 
command lines of
 your program.
  
 @ 
-\section{what}
+
+\section{command what}
 <<what>>=
 ====================================================================
 A.28.  )what
@@ -1964,6 +3074,80 @@ o )set
 o )show
  
 @
+
+\section{syntax while}
+<<while>>=
+====================================================================
+while loops
+====================================================================
+
+The repeat in a loop can be modified by adding one or more while 
+clauses. Each clause contains a predicate immediately following the
+while keyword. The predicate is tested before the evaluation of the 
+body of the loop. The loop body is evaluated whenever the predicate
+in a while clause is true.
+
+The syntax for a simple loop using while is
+
+  while predicate repeat loopbody
+
+The predicate is evaluated before loopbody is evaluated. A while loop
+terminates immediately when predicate evaluates to false or when a
+leave or return expression is evaluted. See )help repeat for more
+information on leave and return.
+
+Here is a simple example of using while in a loop. We first initialize
+the counter.
+
+  i := 1
+   1
+                      Type: PositiveInteger
+
+  while i < 1 repeat
+    output "hello"
+    i := i + 1
+                      Type: Void
+
+The steps involved in computing this example are
+ (1) set i to 1
+ (2) test the condition i < 1 and determine that it is not true
+ (3) do not evaluate the loop body and therefore do not display "hello"
+
+  (x, y) := (1, 1)
+   1
+                      Type: PositiveInteger
+
+If you have multiple predicates to be tested use the logical and
+operation to separate them. Axiom evaluates these predicates from
+left to right.
+
+  while x < 4 and y < 10 repeat
+    output [x,y]
+    x := x + 1
+    y := y + 2
+   [1,1]
+   [2,3]
+   [3,5]
+                      Type: Void
+
+
+A leave expression can be included in a loop body to terminate a loop
+even if the predicate in any while clauses are not false.
+
+  (x, y) := (1, 1)
+   1
+                      Type: PositiveInteger
+
+  while x < 4 and y < 10 repeat
+    if x + y > 7 then leave
+    output [x,y]
+    x := x + 1
+    y := y + 2
+   [1,1]
+   [2,3]
+                      Type: Void
+
+@
 \section{license}
 <<license>>=
 Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]