home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teachapl.zip
/
TEACH.ZIP
/
TEACH14A.ATF
< prev
next >
Wrap
Text File
|
1997-09-19
|
52KB
|
635 lines
XNÉIO 0 1 °
XNÉCT 0 1E²13 °
XCÉFC 1 6 .,*0_² °
XNÉRL 0 16807 °
XCÉPR 1 1 °
XCÉLX 1 5 TEACH °
*(1996 4 6 16 8 10 240) °
FBIND ÉFX 'BIND' 'Σ Binding rules of APL2' °
''' 1. Brackets bind to the left''' °
''' 2. Left arrow binds to the left''' °
''' 3. Dyadic operator binds to the right''' °
''' 4. Strand notation binding''' °
''' 5. Operator binds to its left''' °
''' 6. Function binds to its left''' °
''' 7. Function binds to its right''' °
X ''' 8. Left arrow binds to its right'',r' °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1996 4 6 16 8 11 244) °
FDISPLAY ÉFX 'D╜S DISPLAY A;ÉIO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B' °
'Σ DISPLAY A GENERAL ARRAY IN PICTORIAL FORM' °
'Σ NORMAL CALL IS MONADIC. DYADIC CALL USED ONLY IN' °
'Σ RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.' 'ÉIO╜0' °
'»(0=ÉNC ''S'')/''S╜µA''' 'R╜╞µ,S Σ PSEUDO RANK.' °
'C╜''┐┌└┘'' Σ UR, UL, LL, AND LR CORNERS.' °
'HL╜''─'' Σ HORIZONTAL LINE.' °
'HC╜HL,''Θ╕'',HL,''~+ε'' Σ HORIZONTAL BORDERS.' °
'HT╜HC[(0<R)⌡1+0<╞²1╞,S]' 'ΣW╜,0╧■╞0µΓ(1⌐µA)╞A' °
'HB╜HC[3+3╛(''2⌡~A╧«A'' ÉEA ''1+╞ε0⌡(1⌐⌡/µA)╞,A'')+3⌡1<µµS]' °
'VL╜''│'' Σ VERTICAL LINE.' °
'VB╜VL,''Φ╟'' Σ VERTICAL BORDER.' °
'V╜VB[(1<R)⌡1+0<²1╞²1╟,S]' °
'»(0εµA)/''A╜(1⌐µA)µΓ╞A'' Σ SHOW PROTOTYPE OF EMPTIES.' °
'╕(1<╧A)/GEN' '╕(2<µµA)/D3' °
'D╜«A Σ SIMPLE ARRAYS.' 'W╜1╞µD╜(²2╞1 1,µD)µD' °
'N╜²1+1╟µD' '╕(0=µµA)/SS' °
'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[ °
3]' '╕0' 'SS:HB╜((0 '' '')=╞0µΓA)/'' -''' °
'D╜'' '',('' '',[0]D,[0]HB,Nµ'' ''),'' ''' '╕0' °
'GEN:D╜«DISPLAY■A Σ ENCLOSED ...' 'N╜Dδ.⌠'' ''' °
'D╜(Nδ~1ΦN)≡D' 'D╜(δ≡~'' ''╤D)/D' 'D╜((1,µS)µS)DISPLAY D' °
'╕(2≥µ,S)╟D3E,0' 'D3:D╜0 ²1╟0 1╟«ΓA Σ MULT-DIMENSIONAL ...' °
'W╜1╞µD' 'N╜²1+1╟µD' °
'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[ °
3]' 'D3E:N╜²2+µ,S' °
X 'V╜C[Nµ1],[0]VB[1+0<²2╟,S],[0](((²3+╞µD),N)µVL),[0]C[Nµ2]' 'D╜V,D' °
*(1997 8 17 11 52 3 432) °
FEVAL ÉFX 'EVAL w╢;a╢;c╢;u╢;e╢;r╢' 'Σ Evaluate extensions to APL2' °
'u╢╜''╜''=²1╞a╢╜╞w╢ ╪ w╢╜u╢╟w╢ ╪ (c╢ e╢ r╢)╜ÉEC 2πw╢' °
'╕(1⌠r╢)/L0 ╪ r╢╜3πÉEC 3πw╢ ╪ ╕L1' 'L0:r╢╜3πÉEC╞w╢' °
X 'L1:╕(''╜''⌠²1╞a╢)/L2 ╪ 3πÉEC a╢,''r╢'' ╪ ╕0' 'L2:r╢' °
*(1996 4 6 16 8 11 244) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1996 4 6 16 8 11 244) °
FGO ÉFX 'GO;T;E;B' 'Σ Expression driver' 'L0:B╜E╜''''' 'æ╜'' ''' °
'T╜æ' '╕(^/'' ''=T)/L0' '╕((^/'')OFF ''=5╞6╟T)doif ''EXIT'')/0' °
'╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/L0' °
'''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/L0' '╕B/L0' °
'''This is not a valid APL2 expression''' 'æ╜''*''' °
X '╕(''?''⌠╞1╟æ)/L0' 'E' '╕L0' °
*(1997 8 17 11 49 38 560) °
FHELP ÉFX 'HELP;N;I;T' 'Σ Help to student' '''WHAT TO DO'',r' °
''' ° To get out of the lesson''' ''' ENTER: EXIT''' °
''' ° To log off APL2''' °
''' FIRST, ENTER: EXIT THEN ENTER: )OFF''' °
''' ° To get help''' ''' ENTER: HELP''' °
''' ° When you see the prompt on a blank line''' °
''' ENTER AN APL2 EXPRESSION - OR JUST PRESS: ENTER''' 'do' °
''' ° If you get this line'',r' °
'''This is not a valid APL2 expression'',r,''*'',r' °
''' YOU CAN EITHER''' ''' A. PRESS: ENTER''' °
''' B. PRESS: ? and then ENTER to see what was incorrect''' °
''' in your expression causing that response'',r' 'do' °
'''HINTS'',r' °
'''This lesson is made up of '',(«N╜6),'' components named TEACHx, whe °
re''' '''the x stands for a digit:'',r' 'I╜0' °
'L0:T╜''TEACH'',(«I╜I+1)' 'T,'' '',1╟notb(ÉCR T)[2;]' '╕(N>I)/L0' °
'do' °
'''You may review either of these components separately. To do that,'' °
' °
'''first enter EXIT (and RETURN), then enter the name of the lesson.'' °
' '''component (e.g. TEACH4).'',r' °
'''To re-start the lesson, just enter TEACH'',r' °
'''When the screen fills up, it is a good idea to move the cursor to'' °
' '''the start of a convenient paragraph, and press ENTER'',r' °
'''You may also wish to press PAGE UP to review the prevous pages.''' °
'do' '''RESOURCES'',r' °
'''You may also enter ONE of the following words at a time'',r' °
X '''REVIEW Review of the previous lesson''' 'endd' °
*(1997 8 17 11 51 46 600) °
FNEW ÉFX 'NEW;C╢;E╢;R╢;T╢' 'Σ Driver to experimental extension to APL2' °
'L0:æ╜'' '' ╪ T╢╜æ ╪ T╢╜(+/^\T╢='' '')╟T╢' '(C╢ E╢ R╢)╜ÉEC T╢' °
'╕(T╢╧'''')/L0' '╕(C╢ε4 5)/0' '╕(C╢ε2 3)/L0 ╪ ╕(C╢⌠1)/L1 ╪ R╢ ╪ ╕L0' °
X 'L1:╕(3>µT╢╜(T╢⌠'':'')ΓT╢)/L2 ╪ EVAL T╢ ╪ ╕L0' 'L2:R╢ ╪ ╕L0' °
*(1997 7 1 11 56 53 580) °
FTEACH ÉFX 'TEACH' 'Σ Start lesson #14: APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' °
'TEACH1 Σ The Execute Alternate System function' °
'TEACH2 Σ The Execute Controlled System Function' °
'TEACH3 Σ The Event Type System Variable' °
'TEACH4 Σ Error Messages and the Error Message System variable' °
'TEACH5 Σ Function NEW. Using ÉEC to augument APL2' °
X 'TEACH6 Σ Function EVAL to evaluate non-APL2 expressions' 'problems' °
*(1997 6 28 11 23 52 548) °
FTEACH1 ÉFX 'TEACH1;A;FOO' 'Σ Execute alternate' °
'''As is common with most programming languages, there are problems''' °
'''for which APL2 was not specifically designed. The architects of''' °
'''APL were interested primarily in solving computational and characte °
r''' °
'''manipulation problems. To date by far the most common usage in APL2 °
''' °
'''is for business applications, and to some extent in engineering and °
''' °
'''scientific computations. Since APL2 is not designed for the most''' °
'''effective usage of computer resources, it may not be well suited in °
''' '''the solution of very large (number crunching) problems.''' 'do' °
'''For this reason, APL2 has a number of added on features. We have''' °
'''already studied some of these (System functions and System variable °
s).''' °
'''One of the most important System Functions is the one called NAME'' °
' °
'''ASSOCIATION (ÉNA). Another important family of System Functions''' °
'''is the SHARED VARIABLE family (ÉSVx). These two (ÉNA and ÉSVx), are °
''' °
'''the main vehicles for the effective usage of system resources throu °
gh''' °
'''APL2. Tutorial workspaces on these are available (see TEACH51 TEACH °
51...)''' 'do' ''' CONDITIONAL SYSTEM FUNCTIONS'',r' °
'''There is a class of problems that arises in some applications.''' °
'''Suppose that an APL2 expression proves to be invalid. Normally, APL °
2''' °
'''will cause an INTERRUPT, and display the expression that could not' °
'' °
'''be evaluated. At that point it is up to the user of APL2 to be able °
''' '''to figure out what to do to correct the stopped execution.'',r' °
'''Consider now an application, where it is desired to augument the''' °
'''class of valid APL2 expressions by supporting plain English phrases °
.''' °
'''Any valid APL2 expression would be evaluated normally, so that the' °
'' °
'''application would behave as a normal APL2 session. But in addition, °
''' °
'''a phrase such as for example "What time is it?" would also produce' °
'' '''an appropriate response''' 'do' °
'''The class of problems where this type of activity is common is call °
ed''' °
'''Artificial Intelligence (or AI). In this lesson we will study a num °
ber''' °
'''of System functions as well as some new primitive APL2 functions th °
at''' '''can be used to great advantage in problems of this type.''' °
'do' ''' EXECUTE ALTERNATE (ÉEA)'',r' °
'''Although not part of the APL2 language, the Execute Alternate is on °
e''' °
'''of two ways of evaluating the validity of an APL2 expression.''' °
'''It is a dyadic function of the form L ÉEA R, where L and R must be' °
'' '''character strings, presumably containing APL2 expressions.''' °
'''The right argument is evaluated first. If the evaluation succeeds,' °
'' °
'''the left argument is ignored. If the evaluation fails, then the lef °
t''' '''argument is evaluated'',r' °
'show ''''''∞∞'''' ÉEA ''''∞5'''''' ''''''∞4'''' ÉEA ''''∞∞''''''' °
'''The first two examples illustrate the basic notion of ÉEA. The resu °
lts''' '''are returned as if ÉEA produced a result.''' 'do' °
'''In the next two examples, the expressions in quotes are assignment' °
'' '''statements, and the System Function produces no result.'',r' °
'show ''''''A╜4'''' ÉEA ''''A╜∞5'''''' ''A'' ''''''A╜∞4'''' ÉEA ''''∞' °
''''' ''A''' °
'''The next example shows how a niladic function can be used in the le °
ft''' '''argument.'',r' °
'show ''A╜ÉFX ''''FOO'''' ''''''''''''Not a valid expression'''''''''' °
''''' 'show ''''''FOO'''' ÉEA ''''A╜∞2.1'''''' ''A''' °
'''Finally, ÉEA shows no result for niladic function right argument.'' °
,r' 'show ''''''A╜anything'''' ÉEA ''''FOO'''''' ''A''' °
'''Clearly, ÉEA is a powerful way to handle invalid keyboard entries.' °
'' 'do' °
'''There are problems with ÉEA, as the following examples illustrate'' °
,r' °
'show ''''''A╜4'''' ÉEA ''''A╜∞5'''''' ''µ''''A╜4'''' ÉEA ''''A╜∞5'''' °
''' 'show ''DISPLAY ''''A╜4'''' ÉEA ''''A╜∞5''''''' °
'''Even though the expression shows no result, if we apply functions'' °
' '''to the expression, it behaves as if it did.''' 'do' °
'''Here is another problem'',r' °
'show ''A╜''''anything'''' ÉEA ''''FOO'''''' ''A╜''''FOO'''' ÉEA ''''a °
nything''''''' °
'''If the left or right argument contains an expression that produces' °
'' °
'''no result, then the result of ÉEA cannot be assigned. Since in some °
''' '''applications it is not possible to predict the nature of the''' °
'''arguments to ÉEA, this may pose problems.'',r' °
'''The table below summarizes the requirements for usage of ÉEA:'',r' °
'''RIGHT ARGUMENT LEFT ARGUMENT ÉEA RESULT''' °
'''²²²²²²²²²²²²²² ²²²²²²²²²²²²² ²²²²²²²²²²''' °
'''valid with result arbitrary returns result''' °
'''valid assignment arbitrary no display but result availa °
ble''' '''niladic arbitrary no result''' °
'''invalid valid with result returns result''' °
'''invalid valid assignment no display but result availa °
ble''' '''invalid niladic no result''' °
'''invalid invalid error message'',r' °
'''One drawback in some applications is the indeterminate nature of''' °
'''the result. There is another System Function that avoids that''' °
X '''problem.''' 'endd' °
*(1997 6 28 11 23 27 448) °
FTEACH2 ÉFX 'TEACH2;A;B;C;RC;ET;R' 'Σ Execute controlled' °
'''EXECUTE CONTROLLED (ÉEC)'',r' °
'''The EXECUTE CONTOLLED is a monadic System Function. The right''' °
'''argument is the expression (a character string) to be tested.''' °
'''The function returns a nested three element vector:'',r' °
'show ''DISPLAY ÉEC ''''∞4'''''' ''DISPLAY ÉEC ''''A╜2 2µ∞4''''''' °
'''The expression in the right argument is evaluated, but the result i °
s''' °
'''a three element nested vector. Note, however, that the result is in °
''' °
'''the third element of the vector. If we were to assign the three''' °
'''components of the result to three variables,'',r' °
'show ''(RC ET R)╜ÉEC ''''∞4'''''' ''R''' °
'''then we can retrieve this result.''' 'do' °
'''The next two examples show what happens if the right argument is no °
t''' '''a valid APL2 expression'',r' °
'show ''DISPLAY ÉEC ''''∞∞'''''' ''DISPLAY ÉEC '''')WSID''''''' °
'''The third element of the result contains an Error Message (EM).''' °
'do' °
'''When the Execute Alternate is used, all three elements of the resul °
t''' °
'''should be inspected before a decision can be made on the nature of' °
'' °
'''the evaluation of the right argument. We will now look at the three °
''' '''components of the result.''' 'do' °
'''The first element is called the RETURN CODE. It is a scalar integer °
''' '''with the following meanings'',r' '''Return code Meaning''' °
''' 0 Expression is not executable''' °
''' 1 Expression produces a result''' °
''' 2 Result assigned to a variable''' °
''' 3 Expression with no result (niladic)''' °
''' 4 Branch to an expression (may be empty)''' °
''' 5 ╕ (exit from root function)'',r' °
'''Code 5 means that the current stack of suspended functions is to be °
''' °
'''cleared. If this statement is not clear, it is because we have yet' °
'' '''to discuss this aspect of APL2.''' 'do' °
'''The second component of the result of ÉEC is called the EVENT TYPE. °
''' °
'''We will summarize the meaning of these two integers to the extent t °
Xhat''' '''these are supported by APL2.''' 'endd' °
*(1997 6 28 12 12 6 324) °
FTEACH3 ÉFX 'TEACH3;R;FOO' 'Σ Event Type' '''EVENT TYPE (ÉET)'',r' °
'''The Event Type is a system variable. It is a two element integer''' °
'''vector with default value of (0 0). The contents of ÉET describe''' °
'''the nature of the current evaluation of an APL2 expression. The''' °
'''first integer is a code that describes the Major class of error'',r °
' '''1╙ÉET CONTENTS''' '''²²²²² ²²²²²²²²''' ''' 0 Defaults''' °
''' 1 Resource Errors''' ''' 2 SYNTAX ERRORS''' °
''' 3 VALUE ERRORS''' ''' 4 Implicit argument errors''' °
''' 5 Explicit Argument Errors''' 'do' °
'''The second element of ÉET describes in more detail the nature of''' °
'''that error:'',r' '''DEFAULTS CLASS (0)''' °
'''0 0 No error (default value)''' '''0 1 Unclassified error''' °
'do' '''RESOURCE ERRORS (1)''' '''1 1 INTERRUPT''' °
'''1 2 SYSTEM ERROR''' '''1 3 WS FULL''' °
'''1 4 thru 1 12 SYSTEM LIMIT (system limitations exceeded)'',r' °
'do' '''SYNTAX ERRORS (2)''' °
'''2 1 Required operand or right argument omitted (2⌡)''' °
'''2 2 Ill-formed line ([(])''' '''2 3 Name class (2╜3)''' °
'''2 4 Invalid operation in context ((A╜B)╜2)''' °
'''2 5 Compatibility setting prohibits this syntax'',r' °
'show ''2πÉEC ''''2⌡'''''' ''2πÉEC ''''(∞4)[(]'''''' ''2πÉEC ''''3╜2'' °
''''' '''VALUE ERRORS (3)''' '''3 1 Name with no value''' °
'''3 2 Function with no result'',r' °
'show ''2πÉEC '''')SAVE'''''' ''R╜ÉFX ''''FOO;A'''' ''''A╜5'''''' ''2π °
ÉEC ''''A╜FOO''''''' '''IMPLICIT ARGUMENT ERRORS (4)''' °
'''4 1 ÉPP 4 3 ÉCT 4 5 ÉRL''' °
'''4 2 ÉIO 4 4 ÉFC 4 7 ÉPR'',r' °
'show ''R╜ÉFX ''''U╜FOO;ÉPP'''' ''''U╜2πÉEC ''''''''É╜∞5'''''''''''''' °
''FOO''' '''EXPLICIT ARGUMENT ERRORS (5)''' °
'''5 1 VALENCE ERROR 5 4 DOMAIN ERROR''' °
'''5 2 RANK ERROR 5 5 INDEX ERROR''' °
'''5 3 LENGTH ERROR 5 6 AXIS ERROR'',r' °
'show ''2πÉEC ''''(∞4)[2;]'''''' ''2πÉEC ''''∞3.2''''''' °
'''Detection and classification of errors can be used effectively in'' °
' '''the development of tutorials aimed at teaching APL2.'',r' °
'''We will discuss these events and how they can be used in more detai °
l''' '''when we cover the subject of STACKS in a later lesson.''' °
X 'endd' °
*(1997 9 7 13 14 35 380) °
FTEACH4 ÉFX 'TEACH4;FOO;T' 'Σ Error Messages' '''ERROR MESSAGES'',r' °
'''Whenever APL2 attempts to evaluate an APL2 expression, but fails,'' °
' '''an error message is displayed on the screen. We have already''' °
'''mentioned in lesson 2 the way such errors are handled in these''' °
'''tutorials. Here we will summarize briefly the principal types of''' °
'''errors that one is likely to encounter with routine APL2 usage.''' °
'do' °
'''Although there are many error types, we will now describe only the' °
'' °
'''following:'',r,r,'' AXIS ERROR'',r,'' DOMAIN ERROR'',r,'' INDEX ERR °
OR''' °
''' LENGTH ERROR'',r,'' RANK ERROR'',r,'' SYNTAX ERROR'',r,'' VALUE ER °
ROR''' ''' WS FULL or SYSTEM LIMIT''' 'do' °
'''Whenever the APL2 interpreter detects an invalid expression, it''' °
'''generates a character array called the Event Message. This array''' °
'''is stored in the System Variable ÉEM. If an error occurs, the''' °
'''contents of ÉEM are displayed on the screen (unless the display is' °
'' '''suppressed with a System Function such as ÉEA or ÉEC.)'',r' °
'show ''T╜ÉEM'' ''∞∞'' ''DISPLAY ÉEM'' ''µÉEM''' °
'''The default value of ÉEM is an empty array'',r' °
'show ''DISPLAY T''' °
'''The error message array contains three rows. The first row describe °
s''' °
'''the nature of the error. The second row reproduces the invalid''' °
'''expression causing the ERROR INTERRUPT, and the third row contains °
a''' °
'''caret (^) to indicate the place where the error was detected.'',r' °
'''We will now describe the most common error messages.''' 'do' °
'''An AXIS ERROR ocurrs if the APL2 expression calls for an axis''' °
'''specification that is incompatible with the data'',r' °
'1 show ''+/[2]∞5''' °
'''A DOMAIN ERROR may be produced by a variety of conditions. The most °
''' °
'''common cause is if the data is incompatible with the function'',r' °
'show ''⌡/''''ABC''''''' °
'''If indexing (including pick) calls for non existent data, then''' °
'''an INDEX ERROR will be returned'',r' 'show ''(∞6)[10]''' °
'''A LENGTH ERROR will ocurr if in a dyadic function the lengths''' °
'''of the arguments are incompatible'',r' 'show ''2 4÷3 5 7''' °
'''Whenever a dyadic function calls for arguments with incompatible''' °
'''ranks, a RANK ERROR will be returned'',r' 'show ''2 4+2 2µ∞4''' °
'''If the APL2 expression does not follow the rules of APL syntax,''' °
'''a SYNTAX error will be displayed'',r' 'show ''∞∞''' °
'''A VALUE ERROR will be returned if an expression calls for an undefi °
ned''' '''APL2 object'',r' 'show ''+/anything''' °
'''There may be situations where all of the space reserved for APL2 in °
a''' °
'''workspace is exhausted. (This may happen if an excessively large ar °
ray''' °
'''is generated, or if a recursive function fails to terminate) In mos °
t''' °
'''such cases then either WS FULL or SYSTEM LIMIT will be displayed'', °
Xr' 'show ''10 20 30 40 50µ∞25''' 'endd' °
*(1997 6 30 12 48 16 516) °
FTEACH5 ÉFX 'TEACH5;FN;EVAL;T' °
'Σ Using ÉEC to extend the syntax of APL2' °
'T╜ÉFX ''EVAL W'' ''''''EVAL IS STILL UNDEFINED''''''' °
'''To illustrate the potential of ÉEC, let us assume we wish to extend °
the''' °
'''syntax of APL2. Recall that in lesson 3 we studied DIRECT DEFINITIO °
NS.''' °
'''Although not supported by APL2, direct definition is frequently use °
d''' °
'''in APL literature because of its compact syntax. Here we will borro °
w''' °
'''this syntax to study a possible extension to APL2. In the condition °
al''' °
'''direct definition we saw the following syntactic construct'',r' °
''' label:expression1:expression2:expression3'',r' °
'''The label became the name of a user defined function with result.'' °
' °
'''Whenever this defined function was invoked, the middle expression'' °
' '''(expression2) was evaluated first. If the result was a 1, then''' °
'''expression3 was evaluated. If the result was 0, then expression1''' °
'''was evaluated.''' 'do' °
'''Let us assume that we wish to extend APL2 syntax in the following'' °
' °
'''way. If an expression contains at least 3 colons, it will be assume °
d''' °
'''to be a conditional expression. The syntax, and the rules for''' °
'''evaluation will be as follows:'',r' °
''' [label╜]:exp1:exp2:exp3'',r' °
''' 1. If exp2 returns a 1 then the expression to the right will be''' °
''' evaluated''' °
''' 2. If exp2 returns ANYTHING ELSE (including error message) then''' °
''' exp1 will be evaluated''' ''' 3. Expressions of the form''' °
''' label╜:exp1:exp2:exp3''' °
''' will be acceptable, but require that the leftmost and rightmost °
''' ''' expressions produce a result.''' °
''' 4. Conditional expressions cannot be nested (i.e. the component''' °
''' expressions cannot contain colons)'',r' 'do' °
'''We begin by defining the niladic driver function NEW'',r' °
'show ''FN╜''''NEW;C╢;E╢;R╢;T╢'''' ''''Σ Driver to experimental extens °
ion to APL2''''''' °
'show ''FN╜FN,Γ''''L0:æ╜'''''''' '''''''' ╪ T╢╜æ ╪ T╢╜(+/^\T╢=''' °
''''' '''''''')╟T╢''''''' 'show ''FN╜FN,Γ''''(C╢ E╢ R╢)╜ÉEC T╢''''''' °
'''The first expression simulates the APL2 prompt. Then the expression °
''' °
'''entered at the keyboard with leading blanks removed is evaluated''' °
'''using ÉEC'',r' °
'show ''FN╜FN,''''╕(T╢╧'''''''''''''''')/L0'''' ''''╕(C╢ε4 5)/0''''''' °
'''If keyboard entry is merely Enter, return to the APL2 prompt. Else' °
'' '''if the entry is a branch (╕) exit from NEW'',r' °
'show ''FN╜FN,Γ''''╕(C╢ε2 3)/L0 ╪ ╕(C╢⌠1)/L1 ╪ R╢ ╪ ╕L0''''''' °
'''If the evaluation is an assignment, or a function producing no''' °
'''result, return to the prompt. Else if the expression does produce'' °
' '''a result, display that result'',r' °
'show ''FN╜FN,Γ''''L1:╕(3>µT╢╜(T╢⌠'''''''':'''''''')ΓT╢)/L2 ╪ EVAL T╢ °
╪ ╕L0''''''' 'show ''T╜ÉFX FN,Γ''''L2:R╢ ╪ ╕L0''''''' °
'''If the expression contains at least 3 colons, NEW assumes it to be °
a''' °
'''conditional expression. The local variable T╢ is converted to a nes °
ted''' °
'''vector (with the colons removed). This vector is then entered as th °
e''' °
'''right argument to EVAL. In the last line the contents of R╢ is''' °
'''returned, and the function returns to the prompt. We will provision °
ally''' '''define EVAL to produce a message only''' °
'1 showfn ''EVAL''' 'do' °
'''At the next prompt, enter valid (or invalid) expressions, including °
''' °
'''strings of the form '''':xxx:xxx:xxx''''. TO EXIT from NEW, ENTER ╕ °
'',r' 'show ''NEW''' °
'''Function NEW is transparent to all valid APL2 expressions, but give °
s''' °
'''an error message to SYSTEM COMMANDS and all expressions not contain °
ing''' °
'''three or more colons. Now we are ready to define function EVAL.''' °
X 'endd' °
*(1997 7 1 11 50 35 484) °
FTEACH6 ÉFX 'TEACH6;FN;T;A;B' °
'Σ Define EVAL; function to evaluate conditional expressions' °
'''We are now ready to define function EVAL. We begin with the header' °
'' '''and the comment line'',r' °
'show ''FN╜''''EVAL w╢;a╢;c╢;u╢;e╢;r╢'''' ''''Σ Evaluate extensions to °
APL2''''''' °
'''Function EVAL does not produce a result, since any and all results' °
'' °
'''will be displayed as SIDE EFFECTS. We use lower case letters and ╢ °
to''' °
'''name local variables to minimize chance of conflict with global nam °
es'',r' °
'show ''FN╜FN,Γ''''u╢╜''''''''╜''''''''=²1╞a╢╜╞w╢ ╪ w╢╜u╢╟w╢ ╪ (c╢ e╢ °
r╢)╜ÉEC 2πw╢''''''' °
'''First we must test if the first element of the nested right argumen °
t''' °
'''vector is an assignment. If it is, it is stored in a╢ and removed f °
rom''' '''w╢. Then we apply ÉEC to the second element of w╢'',r' °
'show ''FN╜FN,Γ''''╕(1⌠r╢)/L0 ╪ r╢╜3πÉEC 3πw╢ ╪ ╕L1''''''' °
'''If the result of evaluating the second element is a 1, then evaluat °
e''' '''the third expression of w╢ and branch to L1'',r' °
'show ''FN╜FN,Γ''''L0: r╢╜3πÉEC ╞w╢''''''' °
'''Else evaluate the first expression of w╢.'',r' °
'show ''T╜FN╜FN,Γ''''L1:╕(''''''''╜''''''''⌠²1╞a╢)/L2 ╪ 3πÉEC a╢,''''' °
'''r╢'''''''' ╪ ╕0''''''' 'show ''T╜ÉFX FN,Γ''''L2:r╢''''''' °
'''The last two lines of EVAL tests for the assignment symbol ╜ in a╢. °
If''' °
'''it is absent, the function shows the result r╢. If it is present, t °
he''' °
'''last expression to be evaluated will be stored in the assigned labe °
l.''' 'do' °
'''Before we try out this function, let us look at the EXECUTE CONTLOL °
ED''' °
'''System function when its argument is a character string containing' °
'' '''APL2 expressions separated by the diamond.'',r' °
'show ''3πÉEC ''''∞3 ╪ ∞4'''''' ''DISPLAY 3πÉEC ''''∞3 ╪ ∞4''''''' °
'show ''T╜3πÉEC ''''∞3 ╪ ∞4'''''' ''DISPLAY T''' °
'''In the first example both expressions are displayed AS THEY ARE EXE °
CUTED.''' °
'''In the second example, only the second expression is returned by ÉE °
C.''' °
'''In the third example ÉEC saves only the result of the second expres °
sion.''' 'do' '''Let us now test function EVAL'',r' °
'show ''EVAL ''''∞3 ╪ ∞4'''' ''''3<4'''' ''''∞5 ╪ ∞6''''''' °
'show ''EVAL ''''T╜'''' ''''A╜∞3 ╪ B╜∞4'''' ''''3>4'''' ''''∞5 ╪ ∞6''' °
''' ''DISPLAY A B T''' °
'''Note how the side effects behave on variables A, B and T''' °
'╕(0=ÉNC ''NEW'')/L' °
'''Now try the experimental conditional expressions under function NEW °
''' '''REMEMBER! To exit NEW enter the escape arrow ╕'',r' °
X 'show ''NEW''' 'L:endd' °
*(1997 7 13 12 28 49 504) °
Faddquote ÉFX 'u╜addquote w' °
'Σ Put quotes around a string, and double existing quotes' °
X 'u╜ÉAV[40],((1+w=ÉAV[40])/w),ÉAV[40]' °
*(1997 7 24 13 20 38 476) °
Fav ÉFX 'av;A;N;I;ÉIO' 'Σ Display characters in ÉAV' 'ÉIO╜0' °
'A╜22 78µ'' ''' 'N╜3 0«φ12 22µ1+∞356' 'A[;,(6⌡∞12)°.+2 3 4]╜N' °
'A[;6+6⌡∞12]╜φ12 22µÉAV' 'ΣA[8 10 13;6]╜'' ''' 'A[13;6]╜'' ''' °
X 'A[14+∞8;68 69 70 72]╜'' ''' 'A' °
*(1991 11 11 8 25 13 316) °
Fdate ÉFX 'u╜date w' 'Σ Format date and time of day' 'u╜«6╞w' °
X 'u╜('' ''⌠u)Γu' 'u╜εu,■''-- .. ''' °
XCdig 1 10 1234567890 °
*(1997 9 9 13 0 45 372) °
Fdisclaimer ÉFX 'disclaimer' 'Σ Copyright statement' °
'(10µ'' ''),''Copyright, Z. V. Jizba, 1995,1996,1997'',r' °
''' This and subsequent workspaces labelled TEACHxx are made available °
''' °
'''at no cost to anyone who desires to learn how to use effectively''' °
'''the IBM/OS2 version of APL2.'',r' °
'''This software is provided "AS IS" with no WARRANTY of any kind, eit °
her''' °
'''express or implied. Any risk in its use resides with you, the user °
of''' '''these tutorials.'',r' ''' ACKNOWLEDGEMENTS'',r' °
''' In writing these tutorials, I am greatly indebted to Roy Sykes, wh °
ose''' °
'''excellent lectures increased my understanding of the language.''' °
'''Discussions with the late Harry Bertucelli clarified a number of''' °
'''concepts and caused me to change some improper terminology that was °
''' °
'''used in previous versions of these tutorials. Mr. Benjamin Archer'' °
' °
'''kindly checked out a nearly final version, bringing to my attention °
''' '''some ommisions, misspellings, and invalid terminology.'',r' °
X '''(PRESS ENTER to continue)''' °
*(1997 7 13 12 28 50 508) °
Fdo ÉFX 'do;T;E' 'Σ Expression driver' 'E╜''''' 'æ╜'' ''' 'T╜æ' °
'╕(^/'' ''=T)/0' °
'╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/2' °
'''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/2' °
'''This is not a valid APL2 expression''' 'æ╜''*''' '╕(''?''⌠╞1╟æ)/2' °
X 'E' '╕2' °
*(1997 7 13 12 28 50 508) °
Fdoif ÉFX 'U╢╜V╢ doif W╢;t╢' 'Σ Rule' '╕(^/~U╢╜V╢)/0' °
X '''U╢╜V╢ doif■ W╢'' ÉEA ''»V╢/W╢''' °
*(1997 9 9 12 50 14 444) °
Fendd ÉFX 'endd' 'Σ end of special feature' '20µ''²'' ╪ ╕(4<µÉLC)/0' °
X 'do' °
*(1997 8 17 11 47 41 564) °
Ferase ÉFX 'erase;t;EXIT;GO;HELP;DISPLAY;BIND;REVIEW;RULE;DISCLAIMER' °
'Σ Erase all global functions and variables' 't╜ÉNL 3' °
't╜(~t^.εlc,'' '')≡t' 't╜ÉEX(~t[;∞5]^.=''TEACH'')≡t' 't╜ÉNL 2' °
X 't╜ÉEX(~t^.εlc,'' '')≡t' 't╜ÉNL 4' 't╜ÉEX(~t^.εlc,'' '')≡t' °
*(1997 7 27 13 47 41 608) °
Fevaldd ÉFX 'u╜evaldd w;c;n' 'Σ Evaluate direct definition' 'u╜0' °
'n╜(w∞''Σ'')-1' 'c╜(((n╞w)⌠'':'')Γn╞w),Γ''ΣDD '',(n+1)╟w' °
'╕((1 label╞c)doif ''''''Invalid label'''''')/0' °
'╕((2=µc)doif ''u╜showdd 1╙c'')/0' °
'╕((3=ÉNC╞c)doif ''u╜⌡µÉ╜(╞c),'''' is already defined.'''''')/0' °
'╕((3=µc)doif ''u╜simdd c'')/0' 'c╜(Γ''α∙ aw'')replace■c' °
'u╜ε''u╜'',((''a''εεc[2 3 4])/''a ''),(╞c),'' w;t;b''' °
'u╜u(5πc)(''b╜(t╜'',(3πc),'')/'',addquote ''u╜'',4πc)' °
X 'u╜u,''╕(t doif b)/0''(''u╜'',2πc)' 'u╜╧ÉFX u' °
*(1997 7 25 13 27 52 564) °
Fexit ÉFX 'V exit W;T' 'Σ Exit if too many suspended functions' °
'╕(0⌠ÉNC ''V'')/L0 ╪ V╜10' 'L0:╕(V>µÉLC)/0' °
'''There are too many suspended functions''' '''Please enter '',W' °
X '╕' °
*(1997 7 26 12 33 39 536) °
Fget ÉFX 'U╜V get W;t;T;ÉPR' 'Σ Prompt for response from keyboard' °
'ÉPR╜T╜ÉAV[ÉIO+255] ╪ ╕(0⌠ÉNC ''V'')/L0 ╪ V╜1' 'L0:V╜V╧1' 'æ╜W ╪ t╜æ' °
'U╜(+/^\t=T)╟t' '╕(''╕''⌠╞U)/L1 ╪ ╕' 'L1:╕V/0' 't╜(U⌠'' '')ΓU' °
X 'U╜(µt),(ΓU),t' °
*(1997 7 28 13 33 8 424) °
Fglobals ÉFX 'globals' 'Σ Initialize useful global variables' °
'uc╜''ABCDEFGHIJKLMNOPQRSTUVWXYZ''' °
'lc╜''abcdefghijklmnopqrstuvwxyz''' 'dig╜''1234567890''' °
X 'r╜ÉAV[13+ÉIO]' 'q╜''''''''' °
*(1997 7 3 12 47 6 368) °
Finitialize ÉFX 'initialize;T' 'Σ Initialize workspace' °
'''AT ALL TIMES, TO CONTINUE, PRESS RETURN!'',r' °
'''To see disclaimers enter:'',r,'' disclaimer''' 'do' 'erase' °
'globals' °
'''Make sure the CAP LOCK light on your keyboard (upper right) is ON!' °
X'' 'endd' °
*(1997 7 27 13 14 33 444) °
Flabel ÉFX 'u╜v label w' °
'Σ Return 1 if label w does not begin with a cap' °
'╕(0⌠ÉNC ''v'')/L0 ╪ v╜0' 'L0:v╜v╧1 ╪ w╜εw ╪ ╕v/L1 ╪ ╕(u╜0⌠ÉNC w)/0' °
X 'L1:╕(u╜~^/wεlc,uc,dig)/0' 'u╜w[1]εlc,dig' °
XClc 1 26 abcdefghijklmnopqrstuvwxyz °
*(1997 7 13 12 28 55 528) °
Fnon ÉFX 'non;T;RC;ET;R' 'Σ Ignore keyboard entry' 'æ╜'' ''' 'T╜æ' °
'╕(0=µ(T⌠'' '')/T)/0' '(RC ET R)╜ÉEC T' '╕(0=RC)/2' °
X '╕((1=RC)doif ''R'')/2' '╕2' °
*(1997 7 13 12 28 55 528) °
Fnotb ÉFX 'u╜notb w' 'Σ Remove trailing blanks' °
'╕((1<╧w)doif ''u╜notb■ w'')/0' '╕((1<µµw)doif ''u╜πnotb Γ[2]w'')/0' °
X 'u╜(1-(,'' ''⌠Φw)∞1)╟w' °
*(1997 7 27 12 55 6 496) °
Fproblems ÉFX 'problems' 'Σ Problems' °
'''That is all for this lesson. Remember, if you want to practice,''' °
'''and plan to use direct definitions, be sure to first enter GO.''' °
'''Direct definitions will then be accepted. To exit GO, enter EXIT.'' °
,r' °
'''To erase a previously defined DIRECT DEFINITION FUNCTION, enter'',r °
' ''' )ERASE functionname'',r' °
X '''WARNING! do not use )ERASE on other labels.'',r' °
XCq 0 ' °
XCr 0 °
*(1997 7 13 12 28 56 532) °
Freplace ÉFX 'u╜v replace u;i;r;s' 'Σ Replace elements in v in u' °
'i╜Γ∞µu' 's╜2πv╜(v⌠'' '')Γv' 'i╜⌡r╜i⌡■Γ[1]u°.=╞v' °
X 'u[(εi)/εr]╜s[(εi)/εi⌡■∞µs]' °
*(1997 7 13 12 28 56 532) °
Fround ÉFX 'U╜V round W' 'Σ Half adjust to V th decimal' °
X 'U╜(╛0.5+W⌡10*V)÷10*V' °
*(1997 7 13 12 28 57 536) °
Fshow ÉFX '╢V show ╢W;╢T;╢B' 'Σ Display and execute ╢W' °
'╢T╜(0=ÉNC ''╢V'')doif ''╢V╜0''' °
'╕((0=╧╢W)doif ''show ╢W,'''' '''''')/0' °
'╕((1<╧╢W)doif ''╢V show ■╢W'')/0' ''' '',╢W' °
X '╕((╢V^'':''ε╢W)doif ''╢T╜evaldd ╢W'')/L0' '''ÉEM'' ÉEA ╢W' 'L0:do' °
*(1997 7 13 12 28 57 536) °
Fshowdd ÉFX 'u╜showdd w;a;b;c;r' °
'Σ Display a direct definition function' °
'╕((1=╧w)doif ''u╜showdd Γw'')/u╜0' °
'╕((3⌠ÉNC╞w)doif ''(ε╞w),'''' is not a function'''''')/0' °
'c╜Γ[2]ÉCR╞w' 'c╜notb(2╞c),(Γ''aw α∙'')replace■2╟c' °
'╕((~''ΣDD''╧3╞2πc)doif ''''''Not a direct definition function'''''')/ °
0' 'u╜1' 'b╜('' ''⌠╞c)Γ╞c' 'a╜'' ''' 'r╜2╟3πc' °
'╕((3=µc)doif ''a,(╞w),'''':'''',r,(3<µ2πc)/'''' Σ'''',3╟2πc'')/0' °
'a╜a,(╞w),'':'',(2╟5πc),'':''' 'b╜(+\r=''('')-+\r='')''' 'b╜b∞0' °
X 'a╜a,(²3╟(b-1)╞3╟r),'':'',2╟»(b+2)╟r' 'a,(3<µ2πc)/'' Σ'',3╟2πc' °
*(1997 7 13 12 28 57 536) °
Fshowfn ÉFX 'U╜V showfn W;F;N;T;ÉIO' 'Σ Simulate ╖W[É]' °
'T╜(0=ÉNC ''V'')doif ''V╜0''' 'ÉIO╜0' °
'U╜r,'' '',''╖'',W,''[É]'',(╞V)╞''╖''' 'N╜1╞µF╜ÉCR W' 'N╜«∞N' °
'N╜(N⌠'' '')ΓN' 'F╜(π''['',■N,■Γ''] ''),F' °
'T╜(1<µ,V)doif ''F╜F[1╟V;]'' ''U╜''''''''''' 'U╜²1╟U,r,,F,r' °
X 'U╜((-+/^\'' ''=ΦU)╟U),('' ╖'')[╞V],r' °
*(1997 7 13 12 28 58 540) °
Fsimdd ÉFX 'u╜simdd w;e' 'Σ Direct definition mode' 'u╜0' °
'╕((0⌠ÉNC╞w)doif ''''''Already defined'''''')/0' 'e╜''α''ε2πw' °
'w[2]╜Γ''u╜'',''α∙ aw'' replace 2πw' 'w╜w[1 3 2]' °
X 'w[1]╜Γε''u╜'',(e/''a ''),w[1],'' w''' 'u╜╧ÉFX w' °
*(1992 6 3 9 59 17 424) °
Ftab ÉFX 'U╜V tab W;T;A;B;C;D;E;F;G;M;ÉPW' 'Σ Tabulate list W' °
'T╜(0=ÉNC ''V'')doif ''V╜0''' 'M╜''Invalid data for tabulation''' °
'V╜4╞V' 'ÉPW╜130╛30⌐G╜V[2]+79⌡V[2]=0' °
'L1:╕((1<╧W)doif ''''''W╜∞0'''' ÉEA ''''W╜πW'''''')/L1' °
'╕(((0=µεW)δ2<µµW)doif ''U╜(~V╧4╞0)/M'')/0' °
'T╜(1≥µµU╜«W)doif ''U╜πW╜(U⌠'''' '''')ΓU''' °
'T╜(0<V[1])doif ''U╜(«(Φ1,╞µW)µ(V[3]µ'''' ''''),∞(╞µW)-V[3]),'''' '''' °
,U''' '╕(G<30)/0' 'T╜(F╜µεV[4])+C╜1╟B╜µA╜(V[3],0)╟U' °
'T╜⌐(1╞B)÷1⌐╛(ÉPW+F)÷T' 'U╜(E╜(V[3],C)╞U),[1](B╜T,1╟B)╞A' °
'''D╜εV[4]'' ÉEA ''D╜ÉAV[εV[4]+33⌡V[4]=0]''' 'L0:A╜(T,0)╟A' °
X '╕(0=1╞µA)/0' 'U╜U,(((T+V[3]),µD)µD),E,[1]B╞A' '╕L0' °
*(1997 7 13 12 28 59 544) °
Ftest ÉFX 'U╜V test W;P' °
'Σ Describe problem in W, (correct answer in V)' 'U╜2' 'L1:W' °
'É╜'' ''' 'P╜æ' '''╕L0'' ÉEA ''P╜»P''' '╕(V╧P)/0' °
X 'L0:╕(0=U╜U-1)/0' '''Incorrect. Try again''' '╕L1' °
XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ °
*(1996 4 6 16 8 11 244) °
Fvec ÉFX 'U╜vec' 'Σ Draw 2d vector in plane' °
'U╜r,r,''2- +'',r '': °'',r,''1- °'',r' °
X 'U╜U,'' : °'',r,''0|....|....|'',r,'' 0 1 2'',r' °