home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / apl / cap / read.me < prev   
Text File  |  1993-12-24  |  31KB  |  836 lines

  1. Copyright (C) 1992, 1993 by Thomas Glen Smith.  All rights reserved.
  2. For more information regarding the CAPLIB software package, contact -
  3.  
  4.     Thomas Glen Smith
  5.     3154 West Shady Lane
  6.     Neenah, Wisconsin 54956 
  7.     Telephone (414) 836-2543
  8.     Compuserve:  76207,3343
  9.  
  10. This program is produced by a member of the Association of Shareware
  11. Professionals (ASP). ASP wants to make sure that the shareware
  12. principle works for you. If you are unable to resolve a
  13. shareware-related problem with an ASP member by contacting the member
  14. directly, ASP may be able to help. The ASP Ombudsman can help you
  15. resolve a dispute or problem with an ASP member, but does not provide
  16. technical support for members' products. Please write to the ASP
  17. Ombudsman at 545 Grover Road, Muskegon, MI 49442 or send a CompuServe
  18. message via CompuServe Mail to ASP Ombudsman 70007,3536.
  19.  
  20. The CAPLIB APL Interpreter on this disk is distributed as a Shareware
  21. program.  Individual users may freely copy this disk and share it with
  22. friends and family. Permission to make copies of excerpts from this
  23. text for personal use is hereby granted.  If you like CAPLIB APL and
  24. intend to keep using it, please acquire a license by contacting
  25. Thomas Glen Smith at the above address. The license fee for CAPLIB APL
  26. is $30.  When you register you'll receive a copy of the book
  27. "CAPLIB - APL For Programmers in C" by Thomas Glen Smith.
  28.  
  29. The CAPLIB APL Interpreter also runs on COHERENT (Trademark of Mark
  30. Wiliams Company), an operating system which incorporates much of the
  31. functionality of UNIX.  File CAP\COHERENT\CAPLIB.UST on this disk
  32. contains a version of CAPLIB APL which runs on COHERENT.  The same
  33. subdirectory contains a READ.ME file with instructions on how to load
  34. the software under COHERENT.
  35.  
  36. If you'd like to take advantage of APL facilities in your C programs,
  37. you can do so with the CAPLIB C run-time library.  The CAPLIB APL
  38. Interpreter was written in C using this library.
  39.  
  40. Executable C programs developed by using CAP.LIB routines, other than
  41. those intended to be used as APL interpreters, may be freely distributed
  42. without further payment or other royalties. The CAP.LIB run-time library
  43. may be distributed only as part of a compiled executable program.
  44. The license fee for the CAPLIB C run-time library is $30.
  45.  
  46. Support Policy
  47.  
  48. While every effort is made to ensure the CAPLIB routines and
  49. documentation are free from defects, your sole and exclusive remedy
  50. will be limited to my efforts to fix the problem, or to my refunding
  51. your purchase price for the CAPLIB software if I'm unable to fix it.
  52. You can contact me by mail, or at the Compuserve address indicated
  53. above.
  54.  
  55. I'll try to answer any questions pertaining to usage for a period of
  56. not less than three months after you acquire one of the CAPLIB licenses.
  57. After that, I'll still answer questions, if I can, and have the time.
  58. But I don't intend this to be my life's work.
  59.  
  60.  
  61. What is CAPLIB?
  62.  
  63. CAPLIB is an implementation of APL, as documented in IBM publication
  64. GC26-3847-4, titled "APL Language", Fifth Edition, July 1978. It
  65. contains an interpreter that lets you program directly in APL on a
  66. standard IBM PC or compatible.  To date it's been tested on DOS 3.3
  67. 4.01, and 5.00, with 1 megabyte of memory or more. The APL interpreter
  68. loads in 210K, so there's no reason why it won't work on smaller
  69. machines.
  70.  
  71. Once you've found the best way to solve a problem using the APL
  72. interpreter, you may want to enhance performance by incorporating
  73. that same logic in a C program using calls to routines in the CAPLIB
  74. run-time library, which is available under a separate license. There
  75. are over four hundred routines available.  ANY SINGLE APL STATEMENT
  76. INVOLVING STANDARD APL FUNCTIONS AND OPERATORS CAN BE DIRECTLY
  77. TRANSLATED TO A SINGLE C LANGUAGE STATEMENT USING CALLS TO CAPLIB
  78. ROUTINES.
  79.  
  80. The source programs for the entire CAPLIB package is also
  81. available under a separate license.
  82.  
  83.  
  84. Diskette Format
  85.  
  86. The content of this disk depends on which components of CAPLIB you've
  87. ordered: The diskette contains these files in its root directory,
  88. with the indicated license numbers:
  89.  
  90.     - APL.EXE (License #1): APL interpreter (Shareware).
  91.  
  92.     - APLF.BAT (License #1): Batch program you can elect to use with
  93.       EGA/VGA monitors to see the special set of APL characters (more
  94.       about this later in READ.ME). (Shareware).
  95.  
  96.     - FONT8X16.EXE (License #1): Normal character set that APLF.BAT
  97.       restores when you're done using the APL interpreter. (Shareware).
  98.  
  99.     - APLFONT.EXE (License #1): Special APL character set. (Shareware).
  100.  
  101.     - HELP.APL (License #1):  APL workspace that provides assistance to
  102.       you while you're using the APL interpreter (more about this later
  103.       in READ.ME). (Shareware).
  104.  
  105.     - CAP.LIB (License #2):  BLINK library with all the CAPLIB routines
  106.       you can call from your C programs.  These are documented in the
  107.       book "CAPLIB: APL for Programmers in C," a copy of which you
  108.       should have received along with this diskette if you purchased
  109.       either license #2 or #3.
  110.  
  111.     - \INCLUDE\ (License #2 and #3): Source which may be INCLUDEd in
  112.       your C programs.  For license #2, this subdirectory will contain
  113.       5 files, and for license #3 it will contain 35 files.
  114.  
  115.     - \SOURCE\ (License #2 and #3): For license #2, this subdirectory
  116.       will contain only 6 files, useful in debugging your C programs.
  117.       With license #3 you get 420 files in this subdirectory.
  118.  
  119.     - \HANDBOOK\ (License #1): Here are nine APL workspaces containing
  120.       defined functions modeled after those listed in the "APL Handbook
  121.       of Techniques" published and copyrighted by IBM in April, 1978.
  122.       (Shareware).
  123.  
  124.  
  125. Trying the APL Interpreter
  126.  
  127. To try the APL interpreter, make this diskette current, key "apl" and
  128. press Enter.  The interpreter will prompt you with "APL>". To stop the
  129. interpreter and return to a DOS prompt, key ")off" and press Enter.
  130.  
  131. If you've used APL before and you're reading this for the first time,
  132. you may think ")off" is a typographical error.  It should read ")OFF"
  133. since the APL symbol set doesn't include lower case letters.  CAPLIB
  134. maps the upper case letters in the APL symbol set to the lower case
  135. letters of the PC keyboard.
  136.  
  137. There are also about 27 other symbols on a typical APL keyboard that
  138. don't show up on the standard PC keyboard, and 19 symbols that are
  139. composites, produced by keying one symbol, pressing the backspace key,
  140. and overtyping with a second.  There's also the underscored letters A
  141. to Z. CAPLIB maps all these symbols to a standard PC keyboard.
  142. There's a function that helps you with this mapping while you're using
  143. APL.  To use it, when you see the prompt "APL>" enter
  144. ")copy help helpgroup".  When you see the "APL>" prompt again, try -
  145.  
  146.     help 'I'
  147.  
  148. which will display the following:
  149.  
  150.     I    iota symbol, index generator, index of
  151.     I    index generator, I5  is  1 2 3 4 5
  152.     I    index of, 'abc ' I 'b c a' is 2 4 3 4 1 
  153.  
  154. This is telling you that "I" represents the APL iota symbol, which
  155. invokes two APL functions called "index generator" and "index of." 
  156. An example of "index generator" is
  157.  
  158.     I5
  159.  
  160. which produces the string of numbers "1 2 3 4 5". An example of
  161. "index of" is
  162.  
  163.     'abc ' I 'b c a'
  164.  
  165. which produces the string of numbers "2 4 3 4 1" indicating the "b"
  166. in 'b c a' is located in position 2 in 'abc ', " " (a space) is at
  167. position 4, "c" at position 3, and so on.
  168.  
  169. Once you've done the ")copy help helpgroup" you can enter help 'x'
  170. where x is any character on the keyboard, to get a description of
  171. what that key represents in the APL symbol set.  Just be sure you
  172. surround the character in single quotes.  Entering, for example -
  173.  
  174.     help y
  175.  
  176. may get you an error message like, "59 - Operand not found where
  177. expected during execute."
  178.  
  179. You can also use "help" to find out about specific APL functions.
  180. Suppose you think you want to use the APL factorial function, but
  181. you don't remember exactly how it works.  You can find out by
  182. entering -
  183.  
  184.     help 'factorial'
  185.  
  186. which will display the following:
  187.  
  188.     !    factorial, !5 is 120
  189.  
  190. This is telling you that the exclamation point (!) invokes the
  191. factorial function, and that !5 produces 120, which of course is
  192. 5 X 4 X 3 X 2 X 1, the standard factorial function learned in grade
  193. school algebra.
  194.  
  195.  
  196. Video Display of APL Symbols
  197.  
  198.  
  199. If you invoke the APL command, the PC monitor shows the normal
  200. keyboard characters as you press them.  But if you invoke the APLF,
  201. APL symbols are displayed.  I prefer that "M" be displayed when I
  202. press Shift and the "m" key, and "M" maps in my mind with no trouble
  203. or confusion to the domino APL symbol.  But if you want to see the
  204. APL domino, iota, etc., use APLF.
  205.  
  206.  
  207. APL Tutorial
  208.  
  209.  
  210. This is a brief introduction to the APL language.  A detailed
  211. explanation is in the book "CAPLIB: APL for Programmers in C"
  212. copyright 1992, by Thomas Glen Smith (that's me).  You receive
  213. a copy when you acquire a license for any of the three components
  214. of the CAPLIB software package:
  215.  
  216.   (1) The APL Interpreter.
  217.   (2) C Run-time Library.
  218.   (3) C Run-time Library source.
  219.  
  220. Most of us who claim to be programmers were introduced to the craft
  221. with a procedure-oriented language such as BASIC, FORTRAN, PL/1, or
  222. C.  The keywords and syntax may differ from one to the next, but a
  223. programmer uses similar logic with each of these languages to arrive
  224. at solutions. Their operators typically deal only with one item at a
  225. time, and one must define a loop to iteratively process arrays of
  226. items.  For example, this C program adds 5 numbers and prints the sum:
  227.  
  228. #include <stdio.h>
  229. #include <stdlib.h>
  230. main()
  231. {
  232.      static double a[5] = {11.0, 22.1, 3.2, 43.5, 71.4};
  233.      double sum=0.0;
  234.      int i;
  235.  
  236.     for ( i=0; i<5; i++ ) sum += a[i];
  237.      printf("sum = %5.2f",sum);
  238. }
  239.  
  240. sum = 151.20
  241.  
  242. Contrast the above C program with the solution of the same problem in
  243. APL:
  244.  
  245.     + / 22.1 3.2 43.5 71.4
  246.  
  247.         151.2
  248.  
  249. First, of course, you'll notice the conciseness.  There are pros and
  250. cons to this.  There's the obvious advantage of a smaller source to
  251. maintain. But in a more complicated APL program, when it comes time
  252. to make changes a few months after it was written, it can be difficult
  253. to understand the intent of the program simply by reading the source.
  254. You've heard of read-only memory? Some critics of APL refer to it as
  255. the "write-only" language.
  256.  
  257. Be that as is it may, the real advantage of APL hasn't been pointed
  258. out yet. Namely, that its structure is carried along with data, and
  259. is removed from the program.  Suppose we wanted to change the problem
  260. to find the sum of six numbers instead of five.  In our sample C
  261. program we would need to change the "for" statement to test for i
  262. less than 6 instead of 5. But in APL all we change is the data:
  263.  
  264.     + / 22.1 3.2 43.5 71.4 89.5
  265.  
  266.         240.7
  267.  
  268. If you haven't programmed in APL, because of the simplicity of this
  269. sample problem, you may not realize how significant this is, but
  270. you'll find learning APL alters how you as a programmer solve
  271. problems.
  272.  
  273.  
  274. Overview of APL
  275.  
  276.  
  277. APL consists of three fundamentals: arrays; functions; and operators.
  278. Arrays are structured collections of data, either numbers or
  279. characters. Functions accept arrays as arguments, and produce new
  280. arrays as results. Operators accept both arrays and functions,
  281. applying the functions in special ways, also producing new arrays
  282. as results.
  283.  
  284.  
  285. APL Arrays
  286.  
  287.  
  288. Arrays are the means in APL for organizing and storing data. An array
  289. can consist of either numeric or character data, not both. Arrays
  290. have rank indicating the number of dimensions.  Single items are
  291. called scalars, and have rank 0.  Vectors are zero or more items
  292. ordered in a row, and have rank 1.  A matrix has rows and columns, and
  293. has rank 2.  Higher ranked arrays are just called arrays.
  294.  
  295. Arrays are named and given data values with the assignment function,
  296. which is a left arrow in standard APL, and the pound sign (#) in
  297. CAPLIB:
  298.  
  299.     " a becomes the scalar 3
  300.     a # 3
  301.  
  302.     " b becomes the vector 1 3 5
  303.     b # 1 3 5
  304.  
  305.     " c becomes the character vector 'abc'
  306.     c # 'abc'
  307.  
  308.     " a becomes a new vector and is displayed
  309.     L # a # a + b
  310.  
  311.         4 6 8
  312.  
  313. Several important concepts are demonstrated in the last APL statement
  314. above:
  315.  
  316.   -> APL statements are evaluated right to left, and there is no
  317.      operator precedence, such as multiplication being done before
  318.      addition.
  319.  
  320.   -> APL arrays can change their data values, just like many other
  321.      programming languages, but what is more unusual is that they
  322.      can change their shape.  In this case variable a changed from a
  323.      scalar of rank 0 to a vector or rank 1, dimension 3.
  324.  
  325.   -> You can insert "L#" anywhere in an APL statement to display
  326.      results to that point.  L is the caplib symbol for the APL quad
  327.      symbol.
  328.  
  329.  
  330. APL Functions
  331.  
  332.  
  333. Functions accept arrays as arguments, producing new arrays as results.
  334. They can be either primitive or defined depending on whether they are
  335. built in to the APL system, or defined by you. Defined functions are
  336. the means by which you "program" in APL. Primitive functions can be
  337. scalar or mixed.
  338.  
  339.  
  340. Scalar Functions
  341.  
  342.  
  343. Scalar functions apply to their arguments item-by-item, regardless of
  344. their structure, and if they're dyadic (accepting two arguments),
  345. they generally expect the arguments to be of identical rank and shape.
  346. There is one exception to this rule:  If one argument is a single item,
  347. either a scalar or one-element vector, it will be replicated to match
  348. the number of items in the other argument.  Generally, scalar functions
  349. yield results with shapes identical to their arguments. Addition,
  350. multiplication, and division are examples of scalar functions. There
  351. are only two scalar functions that accept character data arguments.
  352. They are the comparisons equal and not equal.
  353.  
  354.     "addition            subtraction          multiplication
  355.     1 2 3 + 4 5 6        1 2 3 _ 4 5 6        1 2 3 X 4 5 6
  356.  
  357.         5 7 9                -3 -3 -3             4 10 18
  358.  
  359.     "floor               ceiling              reciprocal
  360.     D -3.14 2.718        S -3.14 2.718        % 4 -5
  361.  
  362.         -4 2                 -3 3                 0.25 -0.2
  363.  
  364.     'abc' = 'axc'        'abc' ^= 'axc'
  365.  
  366.         1 0 1                0 1 0
  367.  
  368.  
  369. Mixed Functions
  370.  
  371.  
  372. There can be two reasons why they might be called mixed functions.
  373. First, where they're dyadic, the two arguments don't have to agree
  374. either in shape or in data type.  Usually the left argument is
  375. numeric, giving instructions for manipulation of the right
  376. argument, which can either be numeric or character.
  377.  
  378.     "reshape                         shape 
  379.     L # a # 2 3  R  1 2              R a
  380.  
  381.         1 2 1                            2 3
  382.         2 1 2
  383.  
  384.     "index generator                 index of
  385.     I 5                              'abcdef' I 'cad'
  386.  
  387.         1 2 3 4 5                        3 1 4
  388.  
  389.     "take                            drop
  390.     3 Y 2 4 6 8                      2 U 2 4 6 8
  391.  
  392.         2 4 6                            6 8
  393.  
  394.  
  395. Operators
  396.  
  397.  
  398. Operators accept both arrays and functions, applying the functions
  399. in special ways, producing new arrays as results. There are five
  400. operators:
  401.  
  402.     1) Reduction: Denoted by a slash (/), reduction accepts as its
  403.        left argument a scalar dyadic function, and as its right
  404.        argument a numeric array. It applies the function between
  405.        adjacent items in the array.  If v is a vector +/v produces
  406.        the sum of all elements in v.
  407.  
  408.     2) Scan: Denoted by a backslash or slope (\), scan is related to
  409.        the reduction operator.  It also accepts as its left argument
  410.        a scalar dyadic function, and as its right argument a numeric
  411.        array. The result is equivalent to the catenation of the
  412.        results of applying the scalar dyadic function using reduction
  413.        over successively longer selections from the right argument
  414.        The expression X\2 3 4 produces the result 2 6 24, where 2 is
  415.        the result of X/2, 6 is from X/2 3, and 24 is from X/2 3 4.
  416.  
  417.     3) Axis:  Operators such as scan and reduction described above are
  418.        first defined for vectors, and then applied to arrays of higher
  419.        rank as though they were sets of vectors defined along a
  420.        particular dimension. For example, a matrix has two dimensions,
  421.        rows and columns, and can be considered as a set of vectors
  422.        either running along each row or down each column.  The axis
  423.        operator is denoted by brackets enclosing an expression which
  424.        yields the index of the dimension along which the vector set is
  425.        defined.  For example, if m is a matrix, +/[1]m denotes
  426.        reduction down each column, and +/[2]m reduction across each
  427.        row:
  428.  
  429.  
  430.            L # m # 2 3 R I 6           +/[1]m           +/[2]m
  431.  
  432.                1 2 3                      5 7 9            6 15
  433.                4 5 6
  434.  
  435.  
  436.     4) Inner Product: The dot (.) denotes inner product. Its arguments
  437.        are two scalar dyadic functions and two arrays.  One form, m+.Xn,
  438.        is commonly called the matrix product of linear algebra:
  439.  
  440.            L # m # 2 2 R 2 3 4 5        L # n # 2 3 R 5 + I6
  441.  
  442.                2 3                          6  7  8
  443.                4 5                          9 10 11
  444.  
  445.            m +.X n
  446.  
  447.                39 44 49
  448.                69 78 87
  449.  
  450.     5) Outer Product: Accepting a primitive scalar dyadic function and
  451.        two arrays as arguments, outer product applies the function
  452.        between all possible combinations of items from the left array
  453.        argument with items from the right array argument:
  454.  
  455.            1 2 3  J.X  1 2 3 4 5
  456.  
  457.                1 2 3  4  5
  458.                2 4 6  8 10
  459.                3 6 9 12 15
  460.  
  461.  
  462. Workspaces
  463.  
  464.  
  465. When you create named arrays and defined functions interactively in
  466. APL, they're stored in memory in what is called the "active
  467. workspace." Numerous workspaces can be stored on disk, any one of
  468. which you can load into memory as the active workspace.  You can
  469. modify variables and defined  functions while the workspace is in
  470. memory, then save it back on disk. There are 16 APL System Commands,
  471. all prefixed with a right parenthesis, for manipulating workspaces
  472. and their content:
  473.  
  474.  
  475.  1. )clear -- Clears out the active workspace.  Expunges all variables
  476.     and defined functions so the workspace is empty.
  477.  
  478.  2. )copy wsname object [object...] --  The named object(s) are copied
  479.     from the specified workspace named "wsname" on disk into the active
  480.     workspace.
  481.  
  482.  3. )drop wsname -- The workspace named wsname is deleted from disk.
  483.  
  484.  4. )erase [object...] -- The named object are expunged from the active
  485.     workspace.
  486.  
  487.  5. )fns [a] -- Displays a list of defined functions in the active
  488.     workspace, starting with the optional letter indicated by [a].
  489.  
  490.  6. )group grpname [grpname] [object...] -- The list of objects are
  491.     grouped so they can be easily referenced by the single name
  492.     grpname.
  493.  
  494.  7. )grp grpname -- Displays the membership of the named group.
  495.  
  496.  8. )grps [a] -- Displays the groups in the active workspace, in
  497.     alphabetical order, optionally starting with the letter indicated
  498.     by "a".
  499.  
  500.  9. )load wsname -- Workspace "wsname" is loaded into memory as the
  501.     active workspace.
  502.  
  503. 10. )off -- Leave the interactive APL interpreter, and return to DOS.
  504.  
  505. 11. )pcopy wsname object [object...] -- Identical in function to
  506.     )copy, except a named object will not be replaced if it already
  507.     exists in the active workspace.
  508.  
  509. 12. )save [wsname] -- Saves the active workspace to disk with file
  510.     name "wsname.apl".
  511.  
  512. 13. )si -- Displays the state indicator, showing halted defined
  513.     functions.
  514.  
  515. 14. )sinl -- Same as )si, except local names are listed for each
  516.     defined function.
  517.  
  518. 15. )vars [a] -- Displays a list of variables in the active
  519.     workspace, in alphabetical order, optionally starting with the
  520.     letter indicated by "a".
  521.  
  522. 16. )wsid [wsname] -- If "wsname" is specified, it becomes the name
  523.     of the active workspace.  Otherwise, the name of the active
  524.     workspace is displayed.
  525.  
  526.  
  527. User Defined Functions
  528.  
  529.  
  530. A defined function is created by you, and is the means whereby you
  531. "program" in APL. It consists of a function header followed by one
  532. or more APL statements.  Here's one called "plus" that returns the
  533. sum of its two arguments:
  534.  
  535.     " Lcr lists a character representation of a defined function
  536.     Lcr 'plus'
  537.  
  538.         res # l plus r
  539.         res # l + r
  540.  
  541.     1 + 2 + 3                       1 + 2 plus 3
  542.  
  543.         6                               6
  544.  
  545. The first thing in a defined function is always a function header,
  546. which begins with a template describing the function name and
  547. arguments. This is analogous to the function declarator that appears
  548. at the front of a program written in C.  The template has one of six
  549. forms:
  550.  
  551. Type      With Result    Without Result
  552. Dyadic    r # x f y      x f y    
  553. Monadic   r # f y        f y      
  554. Niladic   r # f          f        
  555.  
  556. where:
  557.  
  558. -> f is the name by which the defined function is known.
  559.  
  560. -> r is the localized name of the variable that will contain the
  561.    result.  At least once during each execution of the defined
  562.    function, an assignment must be made to this name.
  563.  
  564. -> x is the localized name of the left argument of a dyadic defined
  565.    function.
  566.  
  567. -> y is the localized name of the right argument of a dyadic or
  568.    monadic defined function.
  569.  
  570. After the template describing the function name and arguments, you
  571. can optionally include a list, delimited by semicolons, of names to
  572. be localized.  For example, the function header -
  573.  
  574.      a demo b;c;d;e
  575.  
  576. declares demo to be a dyadic function returning no value, with left
  577. and right arguments a and b, and three localized variables c, d, and
  578. e.
  579.  
  580.  
  581. Branching
  582.  
  583.  
  584. Defined functions can have numerous APL statements in them, normally
  585. executed sequentially.  You can change this order by inserting branch
  586. statements, each comprised of a right arrow (this is a dollar sign
  587. ($) in the CAPLIB symbol set) followed by an expression yielding a
  588. scalar or vector. An empty vector means no branch will occur.
  589. Execution continues with the next sequential statement.  Otherwise,
  590. the integer part of the leftmost or only value designates the next
  591. statement to execute, according to these rules:
  592.  
  593.   -> All statements in a defined function are sequentially numbered,
  594.      the function header being 0, the next statement 1, and so on.
  595.  
  596.   -> If the integer derived from the branch statement is negative, 0,
  597.      or greater than the largest statement number in the defined
  598.      function, execution of the function terminates.
  599.  
  600.  
  601. State Indicator
  602.  
  603.  
  604. )Si displays the state indicator, the stack of halted, i.e. suspended
  605. and pendent, functions.  Their names are listed  in order, the most
  606. recently halted first. Each is followed by the bracketed statement
  607. number that was about to be, or was being, executed when the function
  608. was halted.
  609.  
  610. Functions are halted either by an error, such as an attempt to divide
  611. by zero, or by the stop control discussed below. They're called
  612. suspended when this happens, and are flagged in the state indicator
  613. list by *.
  614.  
  615. Pendent functions, those without * next to their names in the state
  616. indicator, are there because they've invoked another function that
  617. either got suspended, or became pendent by calling another function,
  618. and so forth until one finally did get suspended.
  619.  
  620. When a function gets suspended you get control at the terminal.  You
  621. can enter pretty much any statement you like.  You can clear functions
  622. on the state indicator from the last to the preceding suspension by
  623. entering a right arrow ($).  Or you can branch anywhere in the topmost
  624. suspended function by entering a right arrow followed by the statement
  625. number to branch to.
  626.  
  627. You can resume execution at the point of suspension by branching to an
  628. empty vector ($ I0), or to the line counter, Llc.  This is a system
  629. global variable that is a vector holding the current statement numbers
  630. of the functions on the state indicator, in the same order, i.e., the
  631. most recently halted leftmost.
  632.  
  633.  
  634. Stop Control
  635.  
  636.  
  637. For debugging purposes, you can stop any defined function and receive
  638. control just before any particular statement gets executed.  To stop
  639. defined function demo before lines 5 and 9 are executed, for example,
  640. enter the APL statement -
  641.  
  642.     sHdemo # 5 9
  643.  
  644. You'll receive control in the localized environment of demo.  If it
  645. localized variables a and b, then you'll have access only to those
  646. local instances.  You can interrogate and change any variable you have
  647. access to. You can resume execution at any statement n in demo by
  648. entering $n, or you can terminate demo's execution by entering $0.
  649.  
  650.  
  651. Trace Control
  652.  
  653.  
  654. For debugging purposes, you can trace any statement in a defined
  655. function. You'll receive a report on your display each time a
  656. designated statement in a defined function is executed.  To trace
  657. lines 1 thru 5 in defined function demo, for example, enter the
  658. APL statement -
  659.  
  660.     tHdemo # I5
  661.  
  662. The function name, the number of the statement in brackets, and the
  663. final value of the statement is displayed each time it is executed.
  664. A branch statement is indicated by a right arrow ($ in CAPLIB)
  665. followed by the number of the next statement to be executed.
  666.  
  667.  
  668. Del Editor Sample Session
  669.  
  670.  
  671. Part of the standard APL system is a component called the "Del editor".
  672. It's rather crude by today's standards.  It worked great when the only
  673. terminals available were teletypes. This sample session begins by
  674. creating a defined function called sum:
  675.  
  676. The APL interpreter prompts with "APL>".  I tell it I want to enter the
  677. del editor for function sum:
  678.  
  679.     APL> Gsum
  680.     [1]
  681.  
  682. The editor generally prompts for input by displaying the bracketed
  683. statement number it expects you to enter next.  In this case it has
  684. prompted me to enter statement [1].  Because the function is new, the
  685. editor assumes I entered the function header when I entered "Gsum".
  686. It thinks sum is going to be niladic without a returned value.  That's
  687. not the case, so I tell it I want to re-enter the function header by
  688. keying [0]:
  689.  
  690.     [1]      [0]
  691.  
  692. The editor prompts me with [0] and I supply the new function header for
  693. sum:
  694.  
  695.     [0]      z # sum x
  696.  
  697. The editor prompts me with the next sequential statement number, and I
  698. respond with the statement:
  699.  
  700.     [1]      z # + / x
  701.  
  702. The editor prompts me with the next sequential statement number. I ask
  703. to see the entire defined function:
  704.  
  705.     [2]      [L]
  706.  
  707.           G z#sum x
  708.     [1]     z#+/x
  709.           G
  710.     [2]   G
  711.     APL>
  712.  
  713. The editor displays the entire function, placing a G in front of the
  714. function header and after the last statement.  It also lists bracketed
  715. statement numbers at the left margin.  Finally it prompts me again to
  716. enter statement 2, to which I respond "G" to tell it I'm done editing,
  717. and I'm once again prompted with "APL>".
  718.  
  719. Inserting a Statement
  720.  
  721. Suppose I want to add a comment to defined function sum telling what it
  722. does:
  723.  
  724.     APL> Gsum
  725.     [2]      [0.1] " provides vector sums
  726.     [0.11]   [L]
  727.             G z#sum x
  728.     [0.1]    " provides vector sums
  729.     [1]       z#+/x
  730.             G
  731.     [2]      G
  732.     APL>
  733.  
  734. Deleting a Statement
  735.  
  736. Then I change my mind and decide to delete the comment, displaying the
  737. entire function before and after:
  738.  
  739.     APL> Gsum[L]
  740.             G z#sum x
  741.     [1]      " provides vector sums
  742.     [2]       z#+/x
  743.             G
  744.     [3]      [H1]
  745.     [3]      [L]
  746.             G z#sum x
  747.     [2]      z#+/x
  748.             G
  749.     [3]      G
  750.     APL>
  751.  
  752. Editing Statements
  753.  
  754. Now I'll use the statement editing capabilities to transform sum into
  755. defined function mean:
  756.  
  757.     APL> Gsum[L]
  758.             G z#sum x
  759.     [1]       z#+/x
  760.             G
  761.  
  762. First there's the replacement of the function header:
  763.  
  764.     [2]      [0]
  765.     [0]       z#mean x
  766.     [0.1]
  767.  
  768. Now to change statement [1] so it produces the vector means rather
  769. than the sums:
  770.  
  771.     [0.1]    [1L0]
  772.     [1]      z#+/x
  773.  
  774. Entering  "[1L0]" above told the editor to display statement [1] with
  775. the cursor positioned at the end of the statement, but one line lower
  776. on the display.  With standard APL, now you're expected to position
  777. the cursor and key in letters or decimal digits indicating where you
  778. want blanks inserted in the statement, and how many.  Keying a "/"
  779. means delete the character in the statement at that position.  You can
  780. use this if you want to, it'll work. But I just press Enter at this
  781. point.
  782.  
  783. The editor responds by re-displaying the statement with the cursor
  784. positioned on the same line at the right end of the statement. I
  785. deliberately key an unmatched left parenthesis to get the editor to
  786. issue the "unbalanced parenthesis" message and enter a special edit
  787. mode which is not standard APL. In this mode:
  788.  
  789.   -> The left and right arrow keys on the PC keyboard move the cursor
  790.      to new positions in the statement, without changing anything.
  791.  
  792.   -> The Backspace key moves the cursor left, and at the same time
  793.      deletes a character.
  794.  
  795.   -> Pressing any of the alphanumeric keys, e.g. ``K'', inserts that
  796.      character in the statement at the cursor position, and the cursor
  797.      is shifted right one position.
  798.  
  799.     [1]      z#+/x(
  800.     [1]      z#+/x(
  801.                   ^ unbalanced parentheses
  802.     [1]      z#(+/x)%-1Y1,Rx
  803.     [2]      G
  804.     APL>
  805.  
  806. Now let's try the new mean function to see if it works:
  807.  
  808.     APL> Gmean[L]G
  809.     [0]    G  z#mean x
  810.     [1]       z#(+/x)%-1Y1,Rx
  811.            G
  812.     APL> mean 1 2 3 4 5
  813.  
  814.         3
  815.  
  816.     APL> mean 5
  817.  
  818.         5
  819.  
  820. Executing APL statements from a DOS file.
  821.  
  822. You can execute APL statements other than through the keyboard by
  823. first storing them in a text file, named "stmts.tex" for example,
  824. then using DOS pipelining:
  825.  
  826.     apl < stmts.tex
  827.  
  828. Incidentally, you can redirect the output to a printer in the same
  829. fashion:
  830.  
  831.     apl < stmts.tex > prn
  832.  
  833. Be sure to conclude your text file with an )OFF statement.
  834.  
  835. This concludes this read.me file.
  836.