home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / teach.zip / TEACH18A.ATF < prev    next >
Text File  |  1997-09-19  |  62KB  |  762 lines

  1. XNÉIO 0 1                                                                      °
  2. XNÉCT 0 1E²13                                                                  °
  3. XCÉFC 1 6 .,*0_²                                                               °
  4. XNÉRL 0 16807                                                                  °
  5. XCÉPR 1 1                                                                      °
  6. XCÉLX 1 5 TEACH                                                                °
  7. *(1996 4 6 16 10 1 212)                                                        °
  8.  FBIND ÉFX 'BIND' 'Σ Binding rules of APL2'                                    °
  9.   '''  1. Brackets bind to the left'''                                         °
  10.   '''  2. Left arrow binds to the left'''                                      °
  11.   '''  3. Dyadic operator binds to the right'''                                °
  12.   '''  4. Strand notation binding'''                                           °
  13.   '''  5. Operator binds to its left'''                                        °
  14.   '''  6. Function binds to its left'''                                        °
  15.   '''  7. Function binds to its right'''                                       °
  16. X '''  8. Left arrow binds to its right'',r'                                   °
  17. *(1997 8 19 11 27 39 484)                                                      °
  18.  FCtoN ÉFX 'U╜V CtoN W;B;D;E;T' 'Σ Convert character W to numeric'             °
  19.   'E╜''Right argument is not a valid table''' '╕(0⌠ÉNC ''V'')/L0 ╪ V╜0'        °
  20.   'L0:B╜'' ''⌠W╜W,'' ''' '╕(1≥µµW)/L1 ╪ B╜δ≡B ╪ U╜(,(D╜µW)µB)Γ,W ╪ ╕L2'        °
  21.   'L1:U╜BΓ,W ╪ D╜µU' 'L2:B╜+/(B⌠1╟B,0)/B' 'U[(^/■'' ''=U)/∞µU]╜Γ«V'            °
  22.   '''U╜0'' ÉEA ''U╜»■U''' '╕(1=╧U)/L3 ╪ E ╪ ╕0'                                °
  23. X 'L3:╕((µεU)=⌡/B,²1╟D)/L4 ╪ U╜∞0 ╪ E ╪ ╕0' 'L4:U╜((²1╟D),B)µU'                °
  24. *(1997 8 19 11 27 43 500)                                                      °
  25.  FCtoN╢ ÉFX 'CtoN╢;R;ONE' 'Σ Blueprint for function CtoN'                      °
  26.   'Σ Z. V. Jizba, workspace TEACH18, April 6, 1991'                            °
  27.   '''Function CtoN will take a character array W with'''                       °
  28.   '''numeric data, and convert it to a numeric array.'''                       °
  29.   '''     U╜V CtoN W;D;T'''                                                    °
  30.   '''Numbers preceeded by a minus sign will be treated as'''                   °
  31.   '''negative numbers.  Blanks in places where numbers are'''                  °
  32.   '''expected, will be treated as zeros by default. An'''                      °
  33.   '''optional left argument is available to over-ride this'''                  °
  34.   '''"zero default".'',r' 'do' '''THE ALGORITHM OF CtoN'',r'                   °
  35.   '''Here is a listing of function CtoN'',r'                                   °
  36.   'show ''1 showfn ''''CtoN'''''''                                             °
  37.   '''If the left argument is not given, a default value of zero'''             °
  38.   '''assigned to V in line [3]. Next, blanks are identified in'''              °
  39.   '''line [4] as before. The resulting pattern is replicated for'''            °
  40.   '''all rows of the array and the ravelled array is partitioned'''            °
  41.   '''into its tabular elements in line [5]. For scalars and vectors'''         °
  42.   '''partition is made in line [6]. The number of columns is obtained'''       °
  43.   '''in line [7] and blank entries are replaced by the default value'''        °
  44.   '''V in line [8].''' 'do'                                                    °
  45.   '''At this point each element of the nested vector should'''                 °
  46.   '''contain an expression that will evaluate to a single number.'',r'         °
  47.   '''The next step is to evaluate each element of this nested'''               °
  48.   '''vector. If one or more entries fail this evaluation, a zero'''            °
  49.   '''is returned on line [9]. On line [10], if the execute has'''              °
  50.   '''failed, or the argument is a scalar, display E and exit. If'''            °
  51.   '''the numeric vector has the wrong length [11](i.e. one or more'''          °
  52.   '''entries return two or more values), then also display E and exit.''       °
  53.  ,r' '''The numeric table is returned if all these tests are passed'''         °
  54.   'do' '''EXAMPLES:'',r'                                                       °
  55.   'show ''DISPLAY R╜«3 3µ∞9'' ''DISPLAY 10+CtoN R'''                           °
  56.   '''A character array containing numeric data is converted to a'''            °
  57.   '''numeric array.''' 'do' 'show ''R╜2 6µ'''' 12 -5-13 13'''''''              °
  58.   'show ''R'' ''CtoN R'''                                                      °
  59.   '''Negative numbers (with minus signs) are converted correctly'''            °
  60.   'do' 'show ''R[2;2]╜'''' '''''' ''R'' ''CtoN R'''                            °
  61.   '''The conversion works even if the minus sign is not next'''                °
  62.   '''to the numeric value''' 'do'                                              °
  63.   'show ''R[1;2 3]╜'''' '''''' ''R[2;2]╜''''1'''''' ''R'''                     °
  64.   '''By blanking out the entry in row 1, column 1, we form an'''               °
  65.   '''incomplete table''' 'do' 'show ''CtoN R'' ''.123 CtoN R'''                °
  66.   '''Applying CtoN monadically the empty slot is assigned a'''                 °
  67.   '''value of zero. This can be modified using CtoN dyadically.''' 'do'        °
  68.   'show ''CtoN É╜,R'' ''CtoN É╜,R,'''' '''''''                                 °
  69.   '''CtoN now works with vectors (but notice that -5-13 evaluates'''           °
  70.   '''to 8 because this expression contains no blanks)''' 'do'                  °
  71.   'show ''CtoN ''''      '''''''                                               °
  72.   '''And it produces the desired message with a blank vector''' 'do'           °
  73.   'show ''R[1;1 2 3]╜''''ONE'''''' ''R'' ''CtoN R'''                           °
  74.   '''An undefined character string in the array produces an'''                 °
  75.   '''error message''' 'do' 'show ''ONE╜1'' ''CtoN R'''                         °
  76. X '''But when the label is assigned a value, CtoN works.'''                    °
  77. *(1997 9 14 12 30 44 504)                                                      °
  78. XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer'             °
  79. *(1996 4 6 16 10 1 212)                                                        °
  80.  FDISPLAY ÉFX 'D╜S DISPLAY A;ÉIO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B'                °
  81.   'Σ DISPLAY A GENERAL ARRAY IN PICTORIAL FORM'                                °
  82.   'Σ  NORMAL CALL IS MONADIC.  DYADIC CALL USED ONLY IN'                       °
  83.   'Σ    RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.' 'ÉIO╜0'          °
  84.   '»(0=ÉNC ''S'')/''S╜µA''' 'R╜╞µ,S                   Σ PSEUDO RANK.'          °
  85.   'C╜''┐┌└┘''                 Σ UR, UL, LL, AND LR CORNERS.'                   °
  86.   'HL╜''─''                   Σ HORIZONTAL LINE.'                              °
  87.   'HC╜HL,''Θ╕'',HL,''~+ε''      Σ HORIZONTAL BORDERS.'                         °
  88.   'HT╜HC[(0<R)⌡1+0<╞²1╞,S]' 'ΣW╜,0╧■╞0µΓ(1⌐µA)╞A'                              °
  89.   'HB╜HC[3+3╛(''2⌡~A╧«A'' ÉEA ''1+╞ε0⌡(1⌐⌡/µA)╞,A'')+3⌡1<µµS]'                 °
  90.   'VL╜''│''                   Σ VERTICAL LINE.'                                °
  91.   'VB╜VL,''Φ╟''               Σ VERTICAL BORDER.'                              °
  92.   'V╜VB[(1<R)⌡1+0<²1╞²1╟,S]'                                                   °
  93.   '»(0εµA)/''A╜(1⌐µA)µΓ╞A''   Σ SHOW PROTOTYPE OF EMPTIES.'                    °
  94.   '╕(1<╧A)/GEN' '╕(2<µµA)/D3'                                                  °
  95.   'D╜«A                     Σ SIMPLE ARRAYS.' 'W╜1╞µD╜(²2╞1 1,µD)µD'           °
  96.   'N╜²1+1╟µD' '╕(0=µµA)/SS'                                                    °
  97.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  98.  3]' '╕0' 'SS:HB╜((0 '' '')=╞0µΓA)/'' -'''                                     °
  99.   'D╜'' '',('' '',[0]D,[0]HB,Nµ'' ''),'' ''' '╕0'                              °
  100.   'GEN:D╜«DISPLAY■A          Σ ENCLOSED ...' 'N╜Dδ.⌠'' '''                     °
  101.   'D╜(Nδ~1ΦN)≡D' 'D╜(δ≡~''  ''╤D)/D' 'D╜((1,µS)µS)DISPLAY D'                   °
  102.   '╕(2≥µ,S)╟D3E,0' 'D3:D╜0 ²1╟0 1╟«ΓA         Σ MULT-DIMENSIONAL ...'          °
  103.   'W╜1╞µD' 'N╜²1+1╟µD'                                                         °
  104.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  105.  3]' 'D3E:N╜²2+µ,S'                                                            °
  106. X 'V╜C[Nµ1],[0]VB[1+0<²2╟,S],[0](((²3+╞µD),N)µVL),[0]C[Nµ2]' 'D╜V,D'           °
  107. *(1996 4 6 16 10 1 212)                                                        °
  108.  FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type:   )OFF'''         °
  109. X '╕'                                                                          °
  110.  AFD╜('U╜V CtoN W;B;D;E;T')('Σ Convert character W to numeric')('E╜''Rig       °
  111.  ht argument is not a valid table''')('╕(0⌠ÉNC ''V'')/L0 ╪ V╜0')('L0:B╜'       °
  112.  ' ''⌠W╜W,'' ''')('╕(1≥µµW)/L1 ╪ B╜δ≡B ╪ U╜(,(D╜µW)µB)Γ,W ╪ ╕L2')('L1:U╜       °
  113.  BΓ,W ╪ D╜µU ')('L2:B╜+/(B⌠1╟B,0)/B')('U[(^/■'' ''=U)/∞µU]╜Γ«V')('''U╜0'       °
  114.  ' ÉEA ''U╜»■U''')('╕(1=╧U)/L3 ╪ E ╪ ╕0')('L3:╕((µεU)=⌡/B,²1╟D)/L4 ╪ U╜∞       °
  115. X0 ╪ E ╪ ╕0')('L4:U╜((²1╟D),B)µU')                                             °
  116.  AFN╜('CtoN╢;R;ONE')('Σ Blueprint for function CtoN')('Σ Z. V. Jizba, wo       °
  117.  rkspace TEACH18, April 6, 1991')('''Function CtoN will take a character       °
  118.   array W with''')('''numeric data, and convert it to a numeric array.''       °
  119.  ')('''     U╜V CtoN W;D;T''')('''Numbers preceeded by a minus sign will       °
  120.   be treated as''')('''negative numbers.  Blanks in places where numbers       °
  121.   are''')('''expected, will be treated as zeros by default. An''')('''op       °
  122.  tional left argument is available to over-ride this''')('''"zero defaul       °
  123.  t".'',r')('do')('''THE ALGORITHM OF CtoN'',r')('''Here is a listing of        °
  124.  function CtoN'',r')('show ''1 showfn ''''CtoN''''''')('''If the left ar       °
  125.  gument is not given, a default value of zero''')('''assigned to V in li       °
  126.  ne [3]. Next, blanks are identified in''')('''line [4] as before. The r       °
  127.  esulting pattern is replicated for''')('''all rows of the array and the       °
  128.   ravelled array is partitioned''')('''into its tabular elements in line       °
  129.   [5]. For scalars and vectors''')('''partition is made in line [6]. The       °
  130.   number of columns is obtained''')('''in line [7] and blank entries are       °
  131.   replaced by the default value''')('''V in line [8].''')('do')('''At th       °
  132.  is point each element of the nested vector should''')('''contain an exp       °
  133.  ression that will evaluate to a single number.'',r')('''The next step i       °
  134.  s to evaluate each element of this nested''')('''vector. If one or more       °
  135.   entries fail this evaluation, a zero''')('''is returned on line [9]. O       °
  136.  n line [10], if the execute has''')('''failed, or the argument is a sca       °
  137.  lar, display E and exit. If''')('''the numeric vector has the wrong len       °
  138.  gth [11](i.e. one or more''')('''entries return two or more values), th       °
  139.  en also display E and exit.'',r')('''The numeric table is returned if a       °
  140.  ll these tests are passed''')('do')('''EXAMPLES:'',r')('show ''DISPLAY        °
  141.  R╜«3 3µ∞9'' ''DISPLAY 10+CtoN R''')('''A character array containing num       °
  142.  eric data is converted to a''')('''numeric array.''')('do')('show ''R╜2       °
  143.   6µ'''' 12 -5-13 13''''''')('show ''R'' ''CtoN R''')('''Negative number       °
  144.  s (with minus signs) are converted correctly''')('do')('show ''R[2;2]╜'       °
  145.  ''' '''''' ''R'' ''CtoN R''')('''The conversion works even if the minus       °
  146.   sign is not next''')('''to the numeric value''')('do')('show ''R[1;2 3       °
  147.  ]╜'''' '''''' ''R[2;2]╜''''1'''''' ''R''')('''By blanking out the entry       °
  148.   in row 1, column 1, we form an''')('''incomplete table''')('do')('show       °
  149.   ''CtoN R'' ''.123 CtoN R''')('''Applying CtoN monadically the empty sl       °
  150.  ot is assigned a''')('''value of zero. This can be modified using CtoN        °
  151.  dyadically.''')('do')('show ''CtoN É╜,R'' ''CtoN É╜,R,'''' ''''''')('''       °
  152.  CtoN now works with vectors (but notice that -5-13 evaluates''')('''to        °
  153.  8 because this expression contains no blanks)''')('do')('show ''CtoN ''       °
  154.  ''      ''''''')('''And it produces the desired message with a blank ve       °
  155.  ctor''')('do')('show ''R[1;1 2 3]╜''''ONE'''''' ''R'' ''CtoN R''')('''A       °
  156.  n undefined character string in the array produces an''')('''error mess       °
  157.  age''')('do')('show ''ONE╜1'' ''CtoN R''')('''But when the label is ass       °
  158. Xigned a value, CtoN works.''')                                                °
  159. *(1996 4 6 16 10 1 212)                                                        °
  160.  FGO ÉFX 'GO;T;E;B' 'Σ Expression driver' 'L0:B╜E╜''''' 'æ╜''      '''         °
  161.   'T╜æ' '╕(^/'' ''=T)/L0' '╕((^/'')OFF ''=5╞6╟T)doif ''EXIT'')/0'              °
  162.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/L0'                       °
  163.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/L0' '╕B/L0'                                      °
  164.   '''This is not a valid APL2 expression''' 'æ╜''*'''                          °
  165. X '╕(''?''⌠╞1╟æ)/L0' 'E' '╕L0'                                                 °
  166. *(1997 8 19 11 25 17 388)                                                      °
  167.  FHELP ÉFX 'HELP;N;I;T' 'Σ Help to student' '''WHAT TO DO'',r'                 °
  168.   '''  ° To get out of the lesson''' '''       ENTER: EXIT'''                  °
  169.   '''  ° To log off APL2'''                                                    °
  170.   '''       FIRST, ENTER: EXIT  THEN ENTER: )OFF'''                            °
  171.   '''  ° To get help''' '''       ENTER: HELP'''                               °
  172.   '''  ° When you see the cursor on a blank line'''                            °
  173.   '''       ENTER AN APL2 EXPRESSION - OR JUST PRESS: ENTER''' 'do'            °
  174.   '''  ° If you get this line'',r'                                             °
  175.   '''This is not a valid APL2 expression'',r,''*'',r'                          °
  176.   '''        YOU CAN EITHER''' '''           A. PRESS: ENTER'''                °
  177.   '''           B. PRESS: ? and then ENTER to see what was incorrect'''        °
  178.   '''              in your expression causing that response'',r' 'do'          °
  179.   '''HINTS'',r'                                                                °
  180.   '''This lesson is made up of '',(«N╜5),'' components named TEACHx, whe       °
  181.  re''' '''the x stands for a digit:'',r' 'I╜0'                                 °
  182.   'L0:T╜''TEACH'',(«I╜I+1)' 'T,'' '',1╟notb(ÉCR T)[2;]' '╕(N>I)/L0'            °
  183.   'do'                                                                         °
  184.   '''You may review either of these components separately. To do that,''       °
  185.  '                                                                             °
  186.   '''first enter EXIT (and RETURN), then enter the name of the lesson.''       °
  187.  ' '''component (e.g. TEACH4).'',r'                                            °
  188.   '''To re-start the lesson, just enter TEACH'',r'                             °
  189.   '''When the screen fills up, it is a good idea to move the cursor to''       °
  190.  ' '''the start of a convenient paragraph, and press ENTER'',r'                °
  191.   '''You may also wish to press PAGE UP to review the prevous pages.'''        °
  192.   'do' '''RESOURCES'',r'                                                       °
  193.   '''You may also enter ONE of the following words at a time'',r'              °
  194.   '''REVIEW    To review previous lesson'''                                    °
  195. X '''V TIME W  Measure execution time of W repeated V times''' 'endd'          °
  196. *(1997 7 17 12 40 41 536)                                                      °
  197.  FTEACH ÉFX 'TEACH' 'Σ Start lesson #18: APL2 by Zdenek V JIZBA'               °
  198.   'exit ''TEACH''' 'initialize' 'TEACH1 Σ Developing new functions'            °
  199.   'TEACH2 Σ Documentation utility functions'                                   °
  200.   'TEACH3 Σ Building a blueprint function'                                     °
  201.   'TEACH4 Σ Start over by re-designing the utility'                            °
  202. X 'TEACH5 Σ A new blueprint function' 'problems'                               °
  203. *(1997 7 13 11 55 23 504)                                                      °
  204.  FTEACH1 ÉFX 'TEACH1;D;F;FN'                                                   °
  205.   'Σ Developing test and documentation function'                               °
  206.   '''In lesson 17 we studied ways to optimize APL2 code. In this lesson'       °
  207.  ''                                                                            °
  208.   '''we will suggest ways to improve the process of defining new APL2'''       °
  209.   '''functions and operators.'',r' '''     EDITORIAL COMMENTS'',r'             °
  210.   '''Most of the time, when considering writing a function, one simply''       °
  211.  ' '''starts by deciding on its name, and on contents of the header.'''        °
  212.   '''Then, it is often just a matter of developing the APL expressions''       °
  213.  '                                                                             °
  214.   '''that will lead to the desired result.  Once the function is complet       °
  215.  e,'''                                                                         °
  216.   '''it is also a good idea to thoroughly test and document it.'',r'           °
  217.   '''Many people document functions by adding comments. Functions are te       °
  218.  sted''' '''without leaving any trace of the kind of testing.''' 'do'          °
  219.   '''In my opinion a well documented function should not only describe''       °
  220.  '                                                                             °
  221.   '''its objective, but also should describe the kinds of tests that it'       °
  222.  ''                                                                            °
  223.   '''has passed.  In this way, it is possible to determine the scope of'       °
  224.  ''                                                                            °
  225.   '''validity of the function.  What is meant by scope?  A function may'       °
  226.  ''                                                                            °
  227.   '''work fine for all the test cases that the developer has thought of,       °
  228.  '''                                                                           °
  229.   '''but may not work for other equally valid cases that were overlooked       °
  230.  ''' '''or may not even have been considered.'',r'                             °
  231.   '''Suppose we wish to develop a function to convert character tables''       °
  232.  '                                                                             °
  233.   '''to numeric array, but fail to test it for a table containing blanks       °
  234.  ''' '''only. The question of scope is: should we have done so, and'''         °
  235.   '''if not, will the function still work with an array of all blanks?''       °
  236.  ' 'F╜'' "CtoN" '' ╪ D╜'' "CtoN╢" ''' 'do'                                     °
  237.   '''There should be some discipline in the development of new user defi       °
  238.  ned'''                                                                        °
  239.   '''APL functions. In this lesson we will introduce one such discipline       °
  240.  .'''                                                                          °
  241.   '''We will simulate the process of defining a function to convert a'''       °
  242.   '''character array to its numeric equivalent. We will call this functi       °
  243.  on''' 'F,''and also define function'',D,''a kind of BLUEPRINT.'',r'           °
  244.   '''We will illustrate the process of designimg the blueprint first, th       °
  245.  en'''                                                                         °
  246.   '''defining'',F,''. Using'',D,''we will test'',F,''and find it lacking       °
  247.  .'''                                                                          °
  248.   '''This will illustrate what frequently happens. A first attempt is li       °
  249.  kely'''                                                                       °
  250.   '''to produce an inadequate function. At this point it is very temptin       °
  251.  g to'''                                                                       °
  252.   '''continue to "improve" the function by adding more lines of code.'''       °
  253.   '''Given the insight gained in the first try, it may be far more usefu       °
  254.  l'''                                                                          °
  255.   '''to scrap the function and start all over. We will re-define'',F,''a       °
  256.  nd'''                                                                         °
  257.   '''get rid of most of'',(²1╟D),''. Finally we will end with a reasonab       °
  258.  ly''' '''useful function'',F,''and a well documented'',(²1╟D),''.'''          °
  259.   'do'                                                                         °
  260.   'show ''FN╜''''CtoN╢;R;ONE'''' ''''Σ Blueprint for function CtoN''''''       °
  261.  '                                                                             °
  262.   '''The function is niladic since it merely describes an APL2 object. I       °
  263.  t'''                                                                          °
  264.   '''may however produce SIDE EFFECTS. What do we mean by side effects?'       °
  265.  ''                                                                            °
  266.   '''These could include generation of variables, evaluation of APL2'''        °
  267.   '''expressions using defined functions, storage or retrieval of data f       °
  268.  rom'''                                                                        °
  269.   '''files, activation of the printer, or any other activity outside of        °
  270.  the''' '''domain of APL2.''' 'do'                                             °
  271.   '''It is important therefore to isolate such side effects from the'''        °
  272.   '''workspace. Normally this is done by localizing the environment by''       °
  273.  '                                                                             °
  274.   '''placing pertinent labels in the header, and by putting other data''       °
  275.  ' '''in temporary storage (see PUSH and PULL in lesson 15).'',r'              °
  276.   'show ''FN╜FN,Γ''''Σ Z. V. Jizba, workspace TEACH18, April 6, 1991''''       °
  277.  '''                                                                           °
  278.   '''The name of the originator, date and the workspace where the APL2''       °
  279.  '                                                                             °
  280.   '''object was first defined should be available on the documentation''       °
  281.  '                                                                             °
  282.   '''function. It is placed there as a comment since it has no direct'''       °
  283.   '''bearing on the use of the blueprint function. (If the function is''       °
  284.  ' '''redefined by someone else, or moved to another workspace, then'''        °
  285.   '''more comment lines should be added, The older ones should not be'''       °
  286. X '''replaced.)''' 'endd'                                                      °
  287. *(1997 7 13 12 4 40 372)                                                       °
  288.  FTEACH2 ÉFX 'TEACH2;T'                                                        °
  289.   'Σ Describe utility functions that are useful in documentation'              °
  290.   '''UTILITY FUNCTIONS'',r'                                                    °
  291.   '''Before we continue defining blueprint function CtoN╢, we must'''          °
  292.   '''describe several utility functions in this workspace. (We have'''         °
  293.   '''already described these in lesson 16, but we repeat the description       °
  294.  s''' '''here to refresh your memory)'',r'                                     °
  295.   '''Incidentally, all utility functions are fully documented in workspa       °
  296.  ce'''                                                                         °
  297.   '''UTILITY. On completion of this lesson, you should load UTILITY'''         °
  298.   '''and explore all functions documented there.''' 'do' 'T╜'' "do" '''        °
  299.   '''Function'',T,''simulates an APL2 prompt. As long as non-blank'''          °
  300.   '''expressions are entered at the keyboard,'',T,''attempts to evaluate       °
  301.  '''                                                                           °
  302.   '''them. When only blanks are entered (or just Enter is pressed),'',T'       °
  303.   '''exits. This function is useful in documentation, since it allows'''       °
  304.   '''the user to try out sample expressions containing the function that       °
  305.  ''' '''is described.''' 'do'                                                  °
  306.   '''Function "show" simulates the keyboard entry of an APL2 expression.       °
  307.  '''                                                                           °
  308.   '''It is used in documentation to illustrate how a function is to be''       °
  309.  ' '''used. The argument to show must be a string'',r'                         °
  310.   'show ''show ''''∞5'''''''                                                   °
  311.   '''Function "showfn" displays selected lines of a defined function.'''       °
  312.   '''(This function has been generalized.) The header for it now is'',r'       °
  313.   '''     [B [rows]] showfn ''''fn'''''',r'                                    °
  314.   '''The left arguments in square brackets are optional. B is a boolean'       °
  315.  ''                                                                            °
  316.   '''value. A one asks for the display of leading and trailing ╖. Option       °
  317.  ally'''                                                                       °
  318.   '''the boolean scalar may be followed by numeric integer vector giving       °
  319.  ''' '''the line numbers (0 index origin) to be displayed'',r'                 °
  320.   'show ''1 showfn ''''do'''''' ''0 2 3 showfn ''''do'''''''                   °
  321.   'show ''²24╞4╟0 0 showfn ''''do'''''''                                       °
  322.   '''You will also recall the names of global variables. In particular,'       °
  323.  '' ''' "r" acts as the Enter key.''' 'do'                                     °
  324.   '''Finally we also need a utility function called "aq" to support'''         °
  325.   '''this tutorial. It is needed to eliminate excessive use of quotes'',       °
  326.  r' 'show ''ÉFX ''''U╜aq W'''' ''''U╜Γaddquote W'''''''                        °
  327.   '''Here is an example on how this function will be used'',r'                 °
  328.   'show ''T╜''''TEXT'''' ''''Σ Function displaying text'''''''                 °
  329.   'show ''DISPLAY T,Γ''''''''''''Text to be displayed'''''''''''''''           °
  330.   '''using "aq" avoids typing many quotes'',r'                                 °
  331. X 'show ''DISPLAY T,aq''''Text to be displayed''''''' 'endd'                   °
  332. *(1997 8 19 11 22 57 536)                                                      °
  333.  FTEACH3 ÉFX 'TEACH3;C;T;I;FD;FT'                                              °
  334.   'Σ Describe process of defining function CtoN'                               °
  335.   '''     WRITING A BLUEPRINT FUNCTION'',r'                                    °
  336.   'FN╜''CtoN╢;R;ONE'' ''Σ Blueprint for function CtoN'''                       °
  337.   'FN╜FN,Γ''Σ Z. V. Jizba, workspace TEACH18, April 6, 1991'''                 °
  338.   '''Let us now go through the process of defining BLUEPRINT function Ct       °
  339.  oN╢.'''                                                                       °
  340.   '''We will also develop the function CtoN at the same time.'',r'             °
  341.   '''NOTE:(When we illustrate the sample blueprint function, we'''             °
  342.   '''      will begin and end it with a line of bars like this:)'',r'          °
  343.   'ends ''BEGIN (or END)'''                                                    °
  344.   'FN╜FN,aq ''Function CtoN will take a character array W with'''              °
  345.   'FN╜FN,aq ''numeric data, and convert it to a numeric array.'''              °
  346.   'FN╜FN,aq ''     U╜V CtoN W;D;T'''                                           °
  347.   'FN╜FN,aq ''Numbers preceeded by a minus sign will be treated as'''          °
  348.   'FN╜FN,aq ''negative numbers.  Blanks in places where numbers are'''         °
  349.   'FN╜FN,aq ''expected, will be treated as zeros by default. An'''             °
  350.   'FN╜FN,aq ''optional left argument is available to over-ride this'''         °
  351.   'FN╜FN,Γ''''''"zero default".'''',r'' ╪ r'                                   °
  352.   '''Function CtoN╢ begins by displaying text'',r' 'show ''πFN'''              °
  353.   '''This first paragraph describes the basic purpose of the function to       °
  354.  ''' '''be defined. It also includes a display of the header format.'''        °
  355.   'do'                                                                         °
  356.   '''At this point let us also define a provisional sample function CtoN       °
  357.  '',r' 'FD╜''U╜CtoN W;D;T'' ''Σ Convert character array W to numeric'''        °
  358.   'FD╜FD,''D╜µW'' ''T╜^≡W='''' '''''' ''D[2]╜+/~(T⌠1╟T,1)/T'''                 °
  359.   'FD╜FD,Γ''U╜Dµ»,W''' 'show ''ÉFX FD''' '1 showfn ''CtoN'''                   °
  360.   '''Line [2] finds the number of rows and columns of the character tabl       °
  361.  e.'''                                                                         °
  362.   '''Line [3] returns a boolean vector showing all columns that are blan       °
  363.  k.'''                                                                         °
  364.   '''Can we use this vector to determine how many columns of numbers the       °
  365.  re'''                                                                         °
  366.   '''are in the table?  Clearly any string of zeros defines a column.'''       °
  367.   '''So how do we count the number of such strings?  One way would be to       °
  368.  '''                                                                           °
  369.   '''reduce all such strings to a single digit. Line [4] does just that.       °
  370.  '',r' '''Let us verify the expression on line [4] with an example'',r'        °
  371.   'show ''T╜1 1 0 0 0 0 1 0 0 0 1 1 1 1 0'' ''É╜I╜(T⌠1╟T,1)/T'' ''+/~I''       °
  372.  '                                                                             °
  373.   '''Line [5] ravels the character array, executes it and then re-shapes       °
  374.   it.''' 'do'                                                                  °
  375.   '''That looks like it might work. So now we know the number of columns       °
  376.  '''                                                                           °
  377.   '''and rows. Before we proceed, let us try function CtoN on some data'       °
  378.  ',r' 'show ''DISPLAY CtoN «3 3µ∞9'''                                          °
  379.   '''Obviously function CtoN is incorrect, but let us assume that we are       °
  380.  ''' '''not aware of that. We continue defining function CtoN╢'',r'            °
  381.   'show ''FN╜FN,Γ''''show ''''''''CtoN «3 3µ∞9'''''''''''''''                  °
  382.   '''Let us try out this initial version of blueprint function'',r'            °
  383.   'show ''ÉFX FN''' 'ends ''BEGIN''' 'show ''CtoN╢''' 'ends ''END'''           °
  384.   '''What was just illustrated is the usage of a blueprint function to''       °
  385.  ' '''detect bugs un the defined function. This one is easy to fix'',r'        °
  386.   'show ''ÉFX FD,Γ''''U╜Dµ»,W,'''''''' '''''''''''''''                         °
  387.   '''And now before we try CtoN╢ again let us add description of the'''        °
  388.   '''algorithm. How much description? We will try an excessive amount.''       °
  389.  ,r' 'FT╜Γ''1 showfn ''''CtoN'''''''                                           °
  390.   'FT╜FT,aq ''The character array is first analyzed for the number of co       °
  391.  lumns'''                                                                      °
  392.   'FT╜FT,aq ''Line [2] finds the number of rows and columns of the chara       °
  393.  cter'''                                                                       °
  394.   'FT╜FT,aq ''table. Line [3] returns a boolean vector showing all colum       °
  395.  ns'''                                                                         °
  396.   'FT╜FT,aq ''that are blank. Boolean vector T identifies blank columns.       °
  397.   Can'''                                                                       °
  398.   'FT╜FT,aq ''we use this vector to determine how many columns of number       °
  399.  s there'''                                                                    °
  400.   'FT╜FT,aq ''are in the table?  Clearly any string of zeros defines a c       °
  401.  olumn.'''                                                                     °
  402.   'FT╜FT,aq ''So how do we count the number of such strings?  One way wo       °
  403.  uld be to'''                                                                  °
  404.   'FT╜FT,aq ''reduce all such strings to a single digit. Line [4] does j       °
  405.  ust that.'''                                                                  °
  406.   'FT╜FT,Γ''''''Let us verify this expression on an example'''',r'''           °
  407.   'FT╜FT,Γ''show ''''T╜1 1 0 0 0 0 1 0 0 0 1 1 1 1 0'''''''                    °
  408.   'FT╜FT,''show ''''É╜I╜(T⌠1╟T,1)/T'''''' ''show ''''+/~I'''''''               °
  409.   'FT╜FT,aq ''Line [5] ravels the character array, executes it and then        °
  410.  re-shapes it.'''                                                              °
  411.   'FT╜FT,aq ''That looks like it might work. D has the right shape now.'       °
  412.  ''                                                                            °
  413.   'FT╜FT,''do'' ''''''Here are some examples. We first generate characte       °
  414.  r array C:'''''''                                                             °
  415.   'FT╜FT,Γ''show ''''DISPLAY C╜2 5µ'''''''' 2 -5-3 13'''''''''''''''           °
  416.   'FT╜FT,Γ''''''And now we will apply CtoN to this array'''',r'''              °
  417.   'FT╜FT,Γ''show ''''CtoN C'''' ''''C[1;2]╜'''''''' '''''''''''' ''''C''       °
  418.  '' ''''CtoN C'''''''                                                          °
  419.   'FT╜FT,Γ''show ''''CtoN É╜,C,'''''''' '''''''''''' ''''CtoN ''''''''         °
  420.     ''''''''''''''' 'show ''ÉFX FN,FT''' 'do'                                  °
  421.   '''The new version of CtoN╢ can now be used to find other problems.'',       °
  422.  r' '''Let us see how the blueprint function works now!'',r'                   °
  423.   'ends ''BEGIN''' 'show ''CtoN╢''' 'ends ''END'''                             °
  424.   '''Clearly there are problems with function CtoN:'''                         °
  425.   ''' 1. It fails to deal with minus signs used to indicate negative num       °
  426.  bers'''                                                                       °
  427.   ''' 2. It gives an error message when when the argument is a vector'''       °
  428.   ''' 3. It gives an error message when the argument is a vector of blan       °
  429. Xks''' 'endd'                                                                  °
  430. *(1997 7 18 13 8 27 360)                                                       °
  431.  FTEACH4 ÉFX 'TEACH4' 'Σ Another approach to CtoN'                             °
  432.   '''      IS THERE A BETTER WAY?'',r'                                         °
  433.   '''With all the shortcomings of function CtoN, major changes are calle       °
  434.  d for.'''                                                                     °
  435.   '''As these changes are made, the documentation function CtoN╢ should        °
  436.  be'''                                                                         °
  437.   '''updated and used to verify that the modified CtoN behaves as desire       °
  438.  d.''' '''But we should also ask: Is there a better way?''' 'do'               °
  439.   '''  Have we selected the right approach to solve the problem? Is the'       °
  440.  ''                                                                            °
  441.   '''algorithm used in CtoN the best one? And what is meant by "best"?''       °
  442.  '                                                                             °
  443.   '''Before we look for efficient (i.e. fast) solutions, we must also as       °
  444.  k''' '''whether our approach leads to a general solution.'',r'                °
  445.   '''  We should be willing to forgo the quest for speed, and concentrat       °
  446.  e on'''                                                                       °
  447.   '''solving the problem in all of its likely complexities. One of the m       °
  448.  ost'''                                                                        °
  449.   '''difficult things to do is to give up an existing algorithm that too       °
  450.  k so'''                                                                       °
  451.   '''much development time, and start "from scratch" with a clean slate.       °
  452.  '',r'                                                                         °
  453.   '''  Recall that function CtoN does not handle well tables containing'       °
  454.  ''                                                                            °
  455.   '''a minus sign, does not handle table entries with missing data, does       °
  456.  '''                                                                           °
  457.   '''not work with character vectors (as opposed to arrays), and does no       °
  458.  t''' '''work with vectors containing only blanks.'',r'                        °
  459.   '''Let us consider a completely new approach'',r'                            °
  460.   'show ''FD╜''''U╜V CtoN W;B;D;E;T'''' ''''Σ Convert character W to num       °
  461.  eric'''''''                                                                   °
  462.   'show ''FD╜FD,Γ''''E╜''''''''Right argument is not a valid table''''''       °
  463.  '''''''''                                                                     °
  464.   'show ''FD╜FD,Γ''''╕(0⌠ÉNC ''''''''V'''''''')/L0 ╪ V╜0'''''''                °
  465.   '''Local variable E is set to contain a message to indicate invalid ta       °
  466.  ble.'''                                                                       °
  467.   '''This time we start by testing for the presence of left argument. If       °
  468.  ''' '''absent, we form the default (0)''' 'do'                                °
  469.   'show ''FD╜FD,Γ''''L0:B╜'''''''' ''''''''⌠W╜W,'''''''' '''''''''''''''       °
  470.   '''The boolean array B marking all positions of a blank in the array w       °
  471.  ill'''                                                                        °
  472.   '''again be used to identify the number of columns in the numeric tabl       °
  473.  e.'',r'                                                                       °
  474.   'show ''FD╜FD,Γ''''╕(1≥µµW)/L1 ╪ B╜δ≡B ╪ U╜(,(D╜µW)µB)Γ,W ╪ ╕L2'''''''       °
  475.   '''If the argument is of rank 0 or 1, go to the next line. Else use'''       °
  476.   '''partition to generate a nested list of all entries in the table.'''       °
  477.   'do' 'show ''FD╜FD,Γ''''L1:U╜BΓ,W ╪ D╜µU '''''''                             °
  478.   'show ''FD╜FD,Γ''''L2:B╜+/(B⌠1╟B,0)/B'''''''                                 °
  479.   '''For rank 0 and 1 arrays, apply B to partition the data. Then on the       °
  480.  ''' '''next line (L2), get the number of columns in the table.''' 'do'        °
  481.   'show ''FD╜FD,Γ''''U[(^/■'''''''' ''''''''=U)/∞µU]╜Γ«V'''''''                °
  482.   '''Some of the entries may be blank. Fill these with the default value       °
  483.   V.''' 'do'                                                                   °
  484.   'show ''FD╜FD,Γ''''''''''''U╜0'''''''' ÉEA ''''''''U╜»■U''''''''''''''       °
  485.  '                                                                             °
  486.   '''If the execute (») fails for even one table entry, set the result o       °
  487.  f''' '''the attempt to convert the table to numeric to zero.''' 'do'          °
  488.   'show ''FD╜FD,Γ''''╕(1=╧U)/L3 ╪ E ╪ ╕0'''''''                                °
  489.   '''If the rank of the result is 0 (meaning the table is blank or the''       °
  490.  '                                                                             °
  491.   '''execute has failed on one or more entries), display message E and e       °
  492.  xit.''' 'do'                                                                  °
  493.   'show ''FD╜FD,Γ''''L3:╕((µεU)=⌡/B,²1╟D)/L4 ╪ U╜∞0 ╪ E ╪ ╕0'''''''            °
  494.   '''If the number of values does not match the size of the array, then'       °
  495.  ''                                                                            °
  496.   '''also print message E and exit. (This could happen if some entries''       °
  497.  ' '''evaluate to two or more numeric values.)''' 'do'                         °
  498.   'show ''FD╜FD,Γ''''L4:U╜((²1╟D),B)µU'''''''                                  °
  499.   '''When all tests pass, return the properly reshaped table.'''               °
  500. X 'show ''ÉFX FD''' 'endd'                                                     °
  501. *(1997 8 19 11 23 51 516)                                                      °
  502.  FTEACH5 ÉFX 'TEACH5;FD' 'Σ Describing algorithm in blueprint function'        °
  503.   '╕((0=ÉNC ''FN'')doif ''''''Do TEACH3 first!'''''')/0'                       °
  504.   '''Having re-defined function CtoN, we should now re-write CtoN╢.'''         °
  505.   '''We can salvage only the first 11 lines of the old version'',r'            °
  506.   'show ''πFN╜11╞FN''' 'FD╜''do'' ''''''THE ALGORITHM OF CtoN'''',r'''         °
  507.   'FD╜FD,Γ''''''Here is a listing of function CtoN'''',r'''                    °
  508.   'FD╜FD,Γ''show ''''1 showfn ''''''''CtoN'''''''''''''''                      °
  509.   'FD╜FD,aq ''If the left argument is not given, a default value of zero       °
  510.  '''                                                                           °
  511.   'FD╜FD,aq ''assigned to V in line [3]. Next, blanks are identified in'       °
  512.  ''                                                                            °
  513.   'FD╜FD,aq ''line [4] as before. The resulting pattern is replicated fo       °
  514.  r'''                                                                          °
  515.   'FD╜FD,aq ''all rows of the array and the ravelled array is partitione       °
  516.  d'''                                                                          °
  517.   'FD╜FD,aq ''into its tabular elements in line [5]. For scalars and vec       °
  518.  tors'''                                                                       °
  519.   'FD╜FD,aq ''partition is made in line [6]. The number of columns is ob       °
  520.  tained'''                                                                     °
  521.   'FD╜FD,aq ''in line [7] and blank entries are replaced by the default        °
  522.  value''' 'FD╜FD,aq ''V in line [8].''' 'FD╜FD,Γ''do'''                        °
  523.   'FD╜FD,aq ''At this point each element of the nested vector should'''        °
  524.   'FD╜FD,Γ''''''contain an expression that will evaluate to a single num       °
  525.  ber.'''',r'''                                                                 °
  526.   'FD╜FD,aq ''The next step is to evaluate each element of this nested''       °
  527.  '                                                                             °
  528.   'FD╜FD,aq ''vector. If one or more entries fail this evaluation, a zer       °
  529.  o'''                                                                          °
  530.   'FD╜FD,aq ''is returned on line [9]. On line [10], if the execute has'       °
  531.  ''                                                                            °
  532.   'FD╜FD,aq ''failed, or the argument is a scalar, display E and exit. I       °
  533.  f'''                                                                          °
  534.   'FD╜FD,aq ''the numeric vector has the wrong length [11](i.e. one or m       °
  535.  ore'''                                                                        °
  536.   'FD╜FD,Γ''''''entries return two or more values), then also display E        °
  537.  and exit.'''',r'''                                                            °
  538.   'FD╜FD,aq ''The numeric table is returned if all these tests are passe       °
  539.  d''' 'FD╜FD,Γ''do''' 'FD╜FD,Γ''''''EXAMPLES:'''',r'''                         °
  540.   'FD╜FD,Γ''show ''''DISPLAY R╜«3 3µ∞9'''' ''''DISPLAY 10+CtoN R'''''''        °
  541.   'FD╜FD,aq ''A character array containing numeric data is converted to        °
  542.  a''' 'FD╜FD,aq ''numeric array.''' 'FD╜FD,Γ''do'''                            °
  543.   'FD╜FD,Γ''show ''''R╜2 6µ'''''''' 12 -5-13 13'''''''''''''''                 °
  544.   'FD╜FD,Γ''show ''''R'''' ''''CtoN R'''''''                                   °
  545.   'FD╜FD,aq ''Negative numbers (with minus signs) are converted correctl       °
  546.  y''' 'FD╜FD,Γ''do'''                                                          °
  547.   'FD╜FD,Γ''show ''''R[2;2]╜'''''''' '''''''''''' ''''R'''' ''''CtoN R''       °
  548.  '''''                                                                         °
  549.   'FD╜FD,aq ''The conversion works even if the minus sign is not next'''       °
  550.   'FD╜FD,aq ''to the numeric value''' 'FD╜FD,Γ''do'''                          °
  551.   'FD╜FD,Γ''show ''''R[1;2 3]╜'''''''' '''''''''''' ''''R[2;2]╜''''''''1       °
  552.  '''''''''''' ''''R'''''''                                                     °
  553.   'FD╜FD,aq ''By blanking out the entry in row 1, column 1, we form an''       °
  554.  ' 'FD╜FD,aq ''incomplete table''' 'FD╜FD,Γ''do'''                             °
  555.   'FD╜FD,Γ''show ''''CtoN R'''' ''''.123 CtoN R'''''''                         °
  556.   'FD╜FD,aq ''Applying CtoN monadically the empty slot is assigned a'''        °
  557.   'FD╜FD,aq ''value of zero. This can be modified using CtoN dyadically.       °
  558.  ''' 'FD╜FD,Γ''do'''                                                           °
  559.   'FD╜FD,Γ''show ''''CtoN É╜,R'''' ''''CtoN É╜,R,'''''''' ''''''''''''''       °
  560.  '                                                                             °
  561.   'FD╜FD,aq ''CtoN now works with vectors (but notice that -5-13 evaluat       °
  562.  es''' 'FD╜FD,aq ''to 8 because this expression contains no blanks)'''         °
  563.   'FD╜FD,Γ''do''' 'FD╜FD,Γ''show ''''CtoN ''''''''      '''''''''''''''        °
  564.   'FD╜FD,aq ''And it produces the desired message with a blank vector'''       °
  565.   'FD╜FD,Γ''do'''                                                              °
  566.   'FD╜FD,Γ''show ''''R[1;1 2 3]╜''''''''ONE'''''''''''' ''''R'''' ''''Ct       °
  567.  oN R'''''''                                                                   °
  568.   'FD╜FD,aq ''An undefined character string in the array produces an'''        °
  569.   'FD╜FD,aq ''error message''' 'FD╜FD,Γ''do'''                                 °
  570.   'FD╜FD,Γ''show ''''ONE╜1'''' ''''CtoN R'''''''                               °
  571.   'FD╜FD,aq ''But when the label is assigned a value, CtoN works.'''           °
  572.   '''The blueprint function then displays function CtoN, and follows thi       °
  573.  s''' '''by a step by step descrition of the new algorithm'',r'                °
  574.   '''The next section describes the test cases that function CtoN must p       °
  575.  ass.'',r'                                                                     °
  576.   '''NOTE:(If during the development process any of these test cases fai       °
  577.  l,'''                                                                         °
  578.   '''      corrections must be made to CtoN until it works properly. Thi       °
  579.  s'''                                                                          °
  580.   '''      TESTING and CORRECTING phase may require several cycles.)'''        °
  581.   'do' 'show ''FN╜FN,FD'' ''ÉFX FN'''                                          °
  582.   '''And now we can try out the final version of blueprint function CtoN       °
  583. X╢.''' 'do' 'ends ''BEGIN''' 'show ''CtoN╢''' 'ends ''END''' 'endd'            °
  584. *(1997 8 19 11 24 31 440)                                                      °
  585.  FTIME ÉFX 'U╜V TIME W;T'                                                      °
  586.   'Σ Measure execution time of W repeated V times'                             °
  587. X 'U╜60 60 1000¥²3╞ÉTS' 'T╜»■VµΓW' 'U╜(,-U-60 60 1000¥²3╞ÉTS)÷V'               °
  588. *(1997 7 13 12 28 49 504)                                                      °
  589.  Faddquote ÉFX 'u╜addquote w'                                                  °
  590.   'Σ Put quotes around a string, and double existing quotes'                   °
  591. X 'u╜ÉAV[40],((1+w=ÉAV[40])/w),ÉAV[40]'                                        °
  592. *(1997 8 19 11 26 31 448)                                                      °
  593. XFaq ÉFX 'U╜aq W' 'U╜Γaddquote W'                                              °
  594. *(1997 7 24 13 20 38 476)                                                      °
  595.  Fav ÉFX 'av;A;N;I;ÉIO' 'Σ Display characters in ÉAV' 'ÉIO╜0'                  °
  596.   'A╜22 78µ'' ''' 'N╜3 0«φ12 22µ1+∞356' 'A[;,(6⌡∞12)°.+2 3 4]╜N'               °
  597.   'A[;6+6⌡∞12]╜φ12 22µÉAV' 'ΣA[8 10 13;6]╜'' ''' 'A[13;6]╜'' '''               °
  598. X 'A[14+∞8;68 69 70 72]╜'' ''' 'A'                                             °
  599. *(1991 11 11 8 25 13 316)                                                      °
  600.  Fdate ÉFX 'u╜date w' 'Σ Format date and time of day' 'u╜«6╞w'                 °
  601. X 'u╜('' ''⌠u)Γu' 'u╜εu,■''-- .. '''                                           °
  602. XCdig 1 10 1234567890                                                          °
  603. *(1997 9 9 13 0 45 372)                                                        °
  604.  Fdisclaimer ÉFX 'disclaimer' 'Σ Copyright statement'                          °
  605.   '(10µ'' ''),''Copyright, Z. V. Jizba, 1995,1996,1997'',r'                    °
  606.   ''' This and subsequent workspaces labelled TEACHxx are made available       °
  607.  '''                                                                           °
  608.   '''at no cost to anyone who desires to learn how to use effectively'''       °
  609.   '''the IBM/OS2 version of APL2.'',r'                                         °
  610.   '''This software is provided "AS IS" with no WARRANTY of any kind, eit       °
  611.  her'''                                                                        °
  612.   '''express or implied. Any risk in its use resides with you, the user        °
  613.  of''' '''these tutorials.'',r' '''     ACKNOWLEDGEMENTS'',r'                  °
  614.   ''' In writing these tutorials, I am greatly indebted to Roy Sykes, wh       °
  615.  ose'''                                                                        °
  616.   '''excellent lectures increased my understanding of the language.'''         °
  617.   '''Discussions with the late Harry Bertucelli clarified a number of'''       °
  618.   '''concepts and caused me to change some improper terminology that was       °
  619.  '''                                                                           °
  620.   '''used in previous versions of these tutorials. Mr. Benjamin Archer''       °
  621.  '                                                                             °
  622.   '''kindly checked out a nearly final version, bringing to my attention       °
  623.  ''' '''some ommisions, misspellings, and invalid terminology.'',r'            °
  624. X '''(PRESS ENTER to continue)'''                                              °
  625. *(1997 7 13 12 28 50 508)                                                      °
  626.  Fdo ÉFX 'do;T;E' 'Σ Expression driver' 'E╜''''' 'æ╜''      ''' 'T╜æ'          °
  627.   '╕(^/'' ''=T)/0'                                                             °
  628.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/2'                        °
  629.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/2'                                               °
  630.   '''This is not a valid APL2 expression''' 'æ╜''*''' '╕(''?''⌠╞1╟æ)/2'        °
  631. X 'E' '╕2'                                                                     °
  632. *(1997 7 13 12 28 50 508)                                                      °
  633.  Fdoif ÉFX 'U╢╜V╢ doif W╢;t╢' 'Σ Rule' '╕(^/~U╢╜V╢)/0'                         °
  634. X '''U╢╜V╢ doif■ W╢'' ÉEA ''»V╢/W╢'''                                          °
  635. *(1997 9 9 12 50 14 444)                                                       °
  636.  Fendd ÉFX 'endd' 'Σ end of special feature' '20µ''²'' ╪ ╕(4<µÉLC)/0'          °
  637. X 'do'                                                                         °
  638. *(1997 8 19 11 20 26 404)                                                      °
  639.  Fends ÉFX 'ends V' 'Σ end of special feature' 'V,(20µ''²''),''SAMPLE'''       °
  640. X 'do'                                                                         °
  641. *(1997 8 19 11 12 31 392)                                                      °
  642.  Ferase ÉFX                                                                    °
  643.   'erase;t;EXIT;GO;HELP;DISPLAY;BIND;REVIEW;RULE;TIME;DISCLAIMER'              °
  644.   'Σ Erase all global functions and variables' 't╜ÉNL 3'                       °
  645.   't╜(~t^.εlc,'' '')≡t' 't╜ÉEX(~t[;∞5]^.=''TEACH'')≡t' 't╜ÉNL 2'               °
  646. X 't╜ÉEX(~t^.εlc,'' '')≡t' 't╜ÉNL 4' 't╜ÉEX(~t^.εlc,'' '')≡t'                  °
  647. *(1997 7 27 13 47 41 608)                                                      °
  648.  Fevaldd ÉFX 'u╜evaldd w;c;n' 'Σ Evaluate direct definition' 'u╜0'             °
  649.   'n╜(w∞''Σ'')-1' 'c╜(((n╞w)⌠'':'')Γn╞w),Γ''ΣDD '',(n+1)╟w'                    °
  650.   '╕((1 label╞c)doif ''''''Invalid label'''''')/0'                             °
  651.   '╕((2=µc)doif ''u╜showdd 1╙c'')/0'                                           °
  652.   '╕((3=ÉNC╞c)doif ''u╜⌡µÉ╜(╞c),'''' is already defined.'''''')/0'             °
  653.   '╕((3=µc)doif ''u╜simdd c'')/0' 'c╜(Γ''α∙ aw'')replace■c'                    °
  654.   'u╜ε''u╜'',((''a''εεc[2 3 4])/''a ''),(╞c),'' w;t;b'''                       °
  655.   'u╜u(5πc)(''b╜(t╜'',(3πc),'')/'',addquote ''u╜'',4πc)'                       °
  656. X 'u╜u,''╕(t doif b)/0''(''u╜'',2πc)' 'u╜╧ÉFX u'                               °
  657. *(1997 7 25 13 27 52 564)                                                      °
  658.  Fexit ÉFX 'V exit W;T' 'Σ Exit if too many suspended functions'               °
  659.   '╕(0⌠ÉNC ''V'')/L0 ╪ V╜10' 'L0:╕(V>µÉLC)/0'                                  °
  660.   '''There are too many suspended functions''' '''Please enter '',W'           °
  661. X '╕'                                                                          °
  662. *(1997 7 26 12 33 39 536)                                                      °
  663.  Fget ÉFX 'U╜V get W;t;T;ÉPR' 'Σ Prompt for response from keyboard'            °
  664.   'ÉPR╜T╜ÉAV[ÉIO+255] ╪ ╕(0⌠ÉNC ''V'')/L0 ╪ V╜1' 'L0:V╜V╧1' 'æ╜W ╪ t╜æ'        °
  665.   'U╜(+/^\t=T)╟t' '╕(''╕''⌠╞U)/L1 ╪ ╕' 'L1:╕V/0' 't╜(U⌠'' '')ΓU'               °
  666. X 'U╜(µt),(ΓU),t'                                                              °
  667. *(1997 7 28 13 33 8 424)                                                       °
  668.  Fglobals ÉFX 'globals' 'Σ Initialize useful global variables'                 °
  669.   'uc╜''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''                                          °
  670.   'lc╜''abcdefghijklmnopqrstuvwxyz''' 'dig╜''1234567890'''                     °
  671. X 'r╜ÉAV[13+ÉIO]' 'q╜'''''''''                                                 °
  672. *(1997 7 3 12 47 6 368)                                                        °
  673.  Finitialize ÉFX 'initialize;T' 'Σ Initialize workspace'                       °
  674.   '''AT ALL TIMES, TO CONTINUE, PRESS RETURN!'',r'                             °
  675.   '''To see disclaimers enter:'',r,''    disclaimer''' 'do' 'erase'            °
  676.   'globals'                                                                    °
  677.   '''Make sure the CAP LOCK light on your keyboard (upper right) is ON!'       °
  678. X'' 'endd'                                                                     °
  679. *(1997 7 27 13 14 33 444)                                                      °
  680.  Flabel ÉFX 'u╜v label w'                                                      °
  681.   'Σ Return 1 if label w does not begin with a cap'                            °
  682.   '╕(0⌠ÉNC ''v'')/L0 ╪ v╜0' 'L0:v╜v╧1 ╪ w╜εw ╪ ╕v/L1 ╪ ╕(u╜0⌠ÉNC w)/0'         °
  683. X 'L1:╕(u╜~^/wεlc,uc,dig)/0' 'u╜w[1]εlc,dig'                                   °
  684. XClc 1 26 abcdefghijklmnopqrstuvwxyz                                           °
  685. *(1997 7 13 12 28 55 528)                                                      °
  686.  Fnon ÉFX 'non;T;RC;ET;R' 'Σ Ignore keyboard entry' 'æ╜''      ''' 'T╜æ'       °
  687.   '╕(0=µ(T⌠'' '')/T)/0' '(RC ET R)╜ÉEC T' '╕(0=RC)/2'                          °
  688. X '╕((1=RC)doif ''R'')/2' '╕2'                                                 °
  689. *(1997 7 13 12 28 55 528)                                                      °
  690.  Fnotb ÉFX 'u╜notb w' 'Σ Remove trailing blanks'                               °
  691.   '╕((1<╧w)doif ''u╜notb■ w'')/0' '╕((1<µµw)doif ''u╜πnotb Γ[2]w'')/0'         °
  692. X 'u╜(1-(,'' ''⌠Φw)∞1)╟w'                                                      °
  693. *(1997 7 27 12 55 6 496)                                                       °
  694.  Fproblems ÉFX 'problems' 'Σ Problems'                                         °
  695.   '''That is all for this lesson. Remember, if you want to practice,'''        °
  696.   '''and plan to use direct definitions, be sure to first enter GO.'''         °
  697.   '''Direct definitions will then be accepted. To exit GO, enter EXIT.''       °
  698.  ,r'                                                                           °
  699.   '''To erase a previously defined DIRECT DEFINITION FUNCTION, enter'',r       °
  700.  ' '''       )ERASE functionname'',r'                                          °
  701. X '''WARNING! do not use )ERASE on other labels.'',r'                          °
  702. XCq 0 '                                                                        °
  703. XCr 0                                                                         °
  704. *(1997 7 13 12 28 56 532)                                                      °
  705.  Freplace ÉFX 'u╜v replace u;i;r;s' 'Σ Replace elements in v in u'             °
  706.   'i╜Γ∞µu' 's╜2πv╜(v⌠'' '')Γv' 'i╜⌡r╜i⌡■Γ[1]u°.=╞v'                            °
  707. X 'u[(εi)/εr]╜s[(εi)/εi⌡■∞µs]'                                                 °
  708. *(1997 7 13 12 28 56 532)                                                      °
  709.  Fround ÉFX 'U╜V round W' 'Σ Half adjust to V th decimal'                      °
  710. X 'U╜(╛0.5+W⌡10*V)÷10*V'                                                       °
  711. *(1997 7 13 12 28 57 536)                                                      °
  712.  Fshow ÉFX '╢V show ╢W;╢T;╢B' 'Σ Display and execute ╢W'                       °
  713.   '╢T╜(0=ÉNC ''╢V'')doif ''╢V╜0'''                                             °
  714.   '╕((0=╧╢W)doif ''show ╢W,'''' '''''')/0'                                     °
  715.   '╕((1<╧╢W)doif ''╢V show ■╢W'')/0' '''      '',╢W'                           °
  716. X '╕((╢V^'':''ε╢W)doif ''╢T╜evaldd ╢W'')/L0' '''ÉEM'' ÉEA ╢W' 'L0:do'          °
  717. *(1997 7 13 12 28 57 536)                                                      °
  718.  Fshowdd ÉFX 'u╜showdd w;a;b;c;r'                                              °
  719.   'Σ Display a direct definition function'                                     °
  720.   '╕((1=╧w)doif ''u╜showdd Γw'')/u╜0'                                          °
  721.   '╕((3⌠ÉNC╞w)doif ''(ε╞w),'''' is not a function'''''')/0'                    °
  722.   'c╜Γ[2]ÉCR╞w' 'c╜notb(2╞c),(Γ''aw α∙'')replace■2╟c'                          °
  723.   '╕((~''ΣDD''╧3╞2πc)doif ''''''Not a direct definition function'''''')/       °
  724.  0' 'u╜1' 'b╜('' ''⌠╞c)Γ╞c' 'a╜''      ''' 'r╜2╟3πc'                           °
  725.   '╕((3=µc)doif ''a,(╞w),'''':'''',r,(3<µ2πc)/''''   Σ'''',3╟2πc'')/0'         °
  726.   'a╜a,(╞w),'':'',(2╟5πc),'':''' 'b╜(+\r=''('')-+\r='')''' 'b╜b∞0'             °
  727. X 'a╜a,(²3╟(b-1)╞3╟r),'':'',2╟»(b+2)╟r' 'a,(3<µ2πc)/''  Σ'',3╟2πc'             °
  728. *(1997 7 13 12 28 57 536)                                                      °
  729.  Fshowfn ÉFX 'U╜V showfn W;F;N;T;ÉIO' 'Σ Simulate ╖W[É]'                       °
  730.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'ÉIO╜0'                                        °
  731.   'U╜r,''      '',''╖'',W,''[É]'',(╞V)╞''╖''' 'N╜1╞µF╜ÉCR W' 'N╜«∞N'           °
  732.   'N╜(N⌠'' '')ΓN' 'F╜(π''['',■N,■Γ''] ''),F'                                   °
  733.   'T╜(1<µ,V)doif ''F╜F[1╟V;]'' ''U╜''''''''''' 'U╜²1╟U,r,,F,r'                 °
  734. X 'U╜((-+/^\'' ''=ΦU)╟U),('' ╖'')[╞V],r'                                       °
  735. *(1997 7 13 12 28 58 540)                                                      °
  736.  Fsimdd ÉFX 'u╜simdd w;e' 'Σ Direct definition mode' 'u╜0'                     °
  737.   '╕((0⌠ÉNC╞w)doif ''''''Already defined'''''')/0' 'e╜''α''ε2πw'               °
  738.   'w[2]╜Γ''u╜'',''α∙ aw'' replace 2πw' 'w╜w[1 3 2]'                            °
  739. X 'w[1]╜Γε''u╜'',(e/''a ''),w[1],'' w''' 'u╜╧ÉFX w'                            °
  740. *(1992 6 3 9 59 17 424)                                                        °
  741.  Ftab ÉFX 'U╜V tab W;T;A;B;C;D;E;F;G;M;ÉPW' 'Σ Tabulate list W'                °
  742.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'M╜''Invalid data for tabulation'''            °
  743.   'V╜4╞V' 'ÉPW╜130╛30⌐G╜V[2]+79⌡V[2]=0'                                        °
  744.   'L1:╕((1<╧W)doif ''''''W╜∞0'''' ÉEA ''''W╜πW'''''')/L1'                      °
  745.   '╕(((0=µεW)δ2<µµW)doif ''U╜(~V╧4╞0)/M'')/0'                                  °
  746.   'T╜(1≥µµU╜«W)doif ''U╜πW╜(U⌠'''' '''')ΓU'''                                  °
  747.   'T╜(0<V[1])doif ''U╜(«(Φ1,╞µW)µ(V[3]µ'''' ''''),∞(╞µW)-V[3]),'''' ''''       °
  748.  ,U''' '╕(G<30)/0' 'T╜(F╜µεV[4])+C╜1╟B╜µA╜(V[3],0)╟U'                          °
  749.   'T╜⌐(1╞B)÷1⌐╛(ÉPW+F)÷T' 'U╜(E╜(V[3],C)╞U),[1](B╜T,1╟B)╞A'                    °
  750.   '''D╜εV[4]'' ÉEA ''D╜ÉAV[εV[4]+33⌡V[4]=0]''' 'L0:A╜(T,0)╟A'                  °
  751. X '╕(0=1╞µA)/0' 'U╜U,(((T+V[3]),µD)µD),E,[1]B╞A' '╕L0'                         °
  752. *(1997 7 13 12 28 59 544)                                                      °
  753.  Ftest ÉFX 'U╜V test W;P'                                                      °
  754.   'Σ Describe problem in W, (correct answer in V)' 'U╜2' 'L1:W'                °
  755.   'É╜''      ''' 'P╜æ' '''╕L0'' ÉEA ''P╜»P''' '╕(V╧P)/0'                       °
  756. X 'L0:╕(0=U╜U-1)/0' '''Incorrect. Try again''' '╕L1'                           °
  757. XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ                                           °
  758. *(1996 4 6 16 10 2 216)                                                        °
  759.  Fvec ÉFX 'U╜vec' 'Σ Draw 2d vector in plane'                                  °
  760.   'U╜r,r,''2-        +'',r '':      °'',r,''1-    °'',r'                       °
  761. X 'U╜U,'' :  °'',r,''0|....|....|'',r,'' 0    1    2'',r'                      °
  762.