home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH11A.ATF
< prev
next >
Wrap
Text File
|
1997-09-19
|
72KB
|
885 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 4 50 384) °
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 5 21 272) °
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' °
*(1996 4 6 16 5 21 272) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1996 4 6 16 5 21 272) °
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 22 12 51 22 528) °
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╜9),'' 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 To review the previous lesson''' 'endd' °
*(1996 4 6 16 5 21 272) °
FREVIEW ÉFX 'REVIEW' 'Σ Review of inner product' °
'''The inner product operator (also known as the DOT product) applies' °
'' °
'''two functions to a dyadic argument. The operator requires a left''' °
'''and a right function, as well as a left and a right argument.'',r' °
'''Although it will produce a result when the arguments are scalar''' °
'''or vectors, inner product is desidgned primarily to be used with''' °
'''arrays of rank 2 or greater.''' 'do' °
'show ''5+.⌡3'' ''1 2 3+.⌡3 2 1'' ''(2 3µ∞6)+.⌡3 2µ∞6''' °
'''In the first example above, only the left function is applied to''' °
'''the two scalars. The last two examples illustrate the principal''' °
'''characteristic of the inner product. Just as the reduction operator °
''' °
'''reduces one dimension, the inner product reduces two dimensions,''' °
'''namely the trailing one fron the left argument, and the leading one °
''' '''from the right argument.'',r' °
'''Although many primitive functions can be used in the inner product, °
''' '''the most common ones are ^.= and +.⌡'',r' °
'show ''(π''''ONE'''' ''''TWO'''' ''''SIX'''')^.=φπ''''SIX'''' ''''ONE °
''''''' 'show ''(3 3µ∞9)+.⌡3 2µΦ∞6''' °
'''The first example illustrates the usage to find matching rows and'' °
' °
'''columns. The second example illustrates matrix multiplication. We'' °
' °
'''will study this numeric method in more detail in subsequent lessons °
.''' 'do' °
'''The following examples illustrate some more unconventional usage''' °
'''of the inner product operator'',r' °
'show ''(3 2µ(1 2) (3 4) (5 6))δ.ε2 2µ(1 2) (3 4)'' ''(∞4)+.,4 2µ∞8''' °
X 'endd' °
*(1997 7 4 12 17 58 460) °
FTEACH ÉFX 'TEACH' 'Σ Start lesson 11: APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' 'TEACH1 Σ User defined functions' °
'TEACH2 Σ Using QUAD FIX and Canonical representation' °
'TEACH3 Σ Defining function ROMAN' 'TEACH4 Σ The line editor' °
'TEACH5 Σ Editorial on programming styles' °
'TEACH6 Σ Re-entering function definition' °
'TEACH7 Σ The session manager editor' 'TEACH8 Σ Headers' °
X 'TEACH9 Σ Local and global objects' 'problems' °
*(1997 6 17 12 44 35 524) °
FTEACH1 ÉFX 'TEACH1' 'Σ Introduction to defined functions' °
'exit ''TEACH1''' °
'''In the previous lesson we learned a lot about an APL2 operator''' °
'''called the ARRAY PRODUCT. There is more to that operator, but''' °
'''we will postpone that, and take a look in this lesson at user''' °
'''defined functions. To review the previous lesson, enter REVIEW.'',r °
' °
'''Before you continue, you may also wish to review lesson 5 first.''' °
''' [T0 do that, enter EXIT to leave this lesson and then )LOAD TEACH °
5]''' 'do' °
'''In lessons 3 4 and 5 we learned about DIRECT DEFINITION, but we als °
o''' °
'''found that this way of defining new APL2 functions is not supported °
by''' °
'''APL2. In this lesson we will study three ways to define a function. °
''' °
''' (APL2 is available on mainframes as well as on the PC. Mainframe °
''' °
''' versions support editors not currently available on the PC. Her °
e''' ''' we describe only the techniques available on the PC.)''' °
'do' °
'''One way to define an APL2 function is to use the DEL MODE (╖). A se °
cond way''' °
'''is to apply a SYSTEM FUNCTION called QUAD FIX (ÉFX). A third way is °
to use''' '''the APL2 editor.''' 'do' °
'''The ╖ mode form invokes a special APL2 editor that prompts for''' °
'''expressions to be enterd at the keyboard. While in the ╖ mode,''' °
'''it is not possible to evaluate APL2 expressions. Conversely, during °
''' °
'''execution of APL2 expressions, it is not possible to switch to the' °
'' °
'''╖ mode. It is because of this, that you will not be able to test''' °
'''╖ function editing until after the completion of this lesson.'',r' °
'''The second way to define new APL2 functions is with the ÉFX System' °
'' °
'''function. This approach allows you to specify the function as a''' °
'''character array first. The ÉFX function then converts the character °
''' '''array to a user defined function.'',r' °
'''In the third approach, you can access the EDIT pull down menu and'' °
' °
'''select the "Open Object" option. (If the function you wish to defin °
e''' °
'''already exists, there is a faster method: place the cursor on the'' °
' '''name of the function and click twice).''' °
'''We will describe these techniques in more detail in this lesson. We °
will''' °
'''also introduce the supporting SYSTEM FUNCTIONS ÉCR, ÉEX and ÉNC.''' °
X 'endd' °
*(1997 6 16 12 48 15 456) °
FTEACH2 ÉFX 'TEACH2;R;T;FN;AVERAGE' 'Σ Quad fix' 'exit ''TEACH2''' °
'''Suppose we desire to define function AVERAGE. The objective of this °
''' °
'''function is to add the elements of an array by reducing its last''' °
'''dimension, and dividing the sum by the number of elements added'',r °
' 'show ''(+/∞5)÷5'' ''(+/2 3µ∞6)÷3''' °
'''The function AVERAGE is monadic, and will produce a result. Therefo °
re''' °
'''the first thing we have to define is this structural information'', °
r' 'show ''FN╜''''U╜AVERAGE R''''''' °
'''We have generated a character string named FN. The contents of FN i °
s''' °
'''called the HEADER. It describes to APL2 the fact that we are about °
to''' °
'''define a function called AVERAGE, which is monadic, and returns a v °
alue.''' °
'''Next we enter a comment to describe the nature of this function.'', °
r' 'show ''FN╜FN ''''Σ Average of last dimension''''''' °
'''A comment like this is not required, but it is an excellent practic °
e''' '''and is highly recommended'',r' 'show ''FN╜FN,Γ''''U╜+/R''''''' °
'''Can you see why we had to use the idiom ,Γ to catenate the string'' °
' °
'''''''U╜+/R'''' to the nested vector FN? (If you have problems with t °
his,''' °
'''try the expressions DISPLAY FN string, DISPLAY FN,string and''' °
'''DISPLAY FN,Γstring.)'',r' 'show ''DISPLAY FN''' °
'''This first expression generates U by reducing R. To find the averag °
e,''' '''we divide U by the scalar 0¥µR'',r' °
'show ''FN╜FN,Γ''''U╜U÷0¥µR''''''' °
'''Why the expression 0¥µR? This insures that the array +/R is divided °
''' °
'''by a scalar no matter what its rank. (Look at lesson 5 to see why t °
he''' °
'''idiom 0¥ returns the last element of a vector as a scalar.)''' °
'do' 'show ''FN'' ''DISPLAY πFN''' °
'''Either of the two versions of FN, a vector of simple character vect °
ors''' °
'''or a simple character array, can be then used as a right argument t °
o''' '''the APL2 System function ÉFX'',r' °
'show ''ÉFX FN'' ''AVERAGE ∞5'' ''R╜AVERAGE 2 3µ∞6'' ''R''' °
'''To see how the defined function AVERAGE looks, there is another Sys °
tem''' °
'''Function called ÉCR (the CR stands for CANONICAL REPRESENTATION).'' °
,r' 'show ''ÉCR ''''AVERAGE''''''' °
'''Why did we separate the expression (+/R)÷0¥µR into two expressions? °
''' °
'''Actually a combined expression would have worked fine, but we do''' °
'''want to make a point. In a defined function, the evaluation proceed °
s''' °
'''from top to bottom, much the same as if we had written the individu °
al''' °
'''expressions one after the other. So when we enter AVERAGE ∞5, the'' °
' °
'''function first assigns to R the result of evaluation of ∞5. Then it °
''' °
'''finds the comment line which it ignores. The next line U╜+/R is''' °
'''evaluated, and then U╜U÷0¥µR completes the algorithm. The final val °
ue''' °
'''of U is then returned. If this value is assigned to a variable as i °
n''' °
'''the second example, the assignment is made in the usual manner.''' °
'do' °
'''What would happen if we were to try fixing a function with invalid' °
'' '''arguments?'',r' 'show ''ÉFX ''''U╜5TEST'''' ''''U╜1''''''' °
'''In the example we have tried to fix a function named 5TEST. Names i °
n''' °
'''APL2 are not allowed beginning with digits. The fixing process fail °
ed,''' °
'''and the return is an integer (actually the 1 means that the error'' °
' '''was detected in the first character vector.)''' 'do' °
'''The ÉFX system function also accepts a four element boolean left''' °
'''argument. The values control execution and the ability to display t °
he''' '''defined function.''' 'do' °
'''It is not always possible to solve problems as in function AVERAGE. °
In''' °
'''some algorithm it may be necessary to make decisions, and to procee °
d''' °
'''according to such decisions. This means that we need a way to skip' °
'' °
'''certain expressions (essentially a GO TO branch). To see how APL2'' °
X' '''handles this problem, we will define another function.''' 'endd' °
*(1997 6 17 12 52 3 428) °
FTEACH3 ÉFX 'TEACH3;R;T;ROMAN;RO;RX;FN;AVERAGE' °
'Σ Branching and labels' 'exit ''TEACH3''' °
'''In lesson 5 we solved the problem of converting an Arabic number''' °
'''to Roman notation. We defined function ROMAN, and two additional''' °
'''functions, RO and RX, to be used as subroutines.'',r' °
'1 show ''ROMAN:RO 10 10 10 10ÿ∙:∙>3999:''''This number is too large'' °
''''' °
'T╜''RO:(∙[1]µ''''M''''),(''''CDM''''RX ∙[2]),(''''XLC''''RX ∙[3]),''' °
'IVX''''RX ∙[4]''' '1 show T' °
'1 show ''RX:((∙>4)µα[2]),(5|∙)µα[1]:4=5|∙:α[1,2+∙=9]''' °
'show ''ROMAN 27''' °
'''Function ROMAN calls on function RO, and this function in turn call °
s on''' °
'''function RX. This is a reasonable way to solve problems with APL2. °
Let''' '''us now define this function using the ÉFX approach.'',r' °
'''As before, we begin with the header'',r' °
'show ''FN╜''''U╜ROMAN ARABIC''''''' °
'''Note that we labelled the argument to ROMAN ''''ARABIC''''. This is °
''' °
'''perfectly valid. APL2 will understand that U and ARABIC are variabl °
es.''' '''We can now continue defining function ROMAN.'',r' °
'show ''FN╜FN ''''Σ To convert Arabic number to Roman notation''''''' °
'''As before we begin with a comment. Now let us consider the algorith °
m.''' °
'''Right away we see that we have a problem. We need to decide whether °
''' °
'''the value of the right argument to ROMAN is greater than 3999. If i °
t is,''' '''then we merely return the string'',r' °
''' ''''This number is too large'''''',r' °
'''If ARABIC is less than 4000, we apply expression RO 10 10 10 10ÿARA °
BIC''' 'do' 'show ''FN╜FN,Γ''''╕(ARABIC<4000)/L0''''''' °
'''The right arrow (╕) is a symbol understood by the portion of APL2'' °
' °
'''that evaluates user defined functions. It has no meaning within''' °
'''stand alone APL2 expressions.''' 'do' °
'''Within user defined functions, it tells the APL2 INTERPRETER to''' °
'''ignore the normal sequence of expressions, but instead to find''' °
'''the expression that begins with the string ''''L0''''.'',r' °
'''This branch will take place only if the expression to the right of' °
'' '''the ╕ returns a value other than null.''' 'do' °
'show ''FN╜FN,Γ''''U╜''''''''This number is too large.''''''''''''''' °
'''If ARABIC is greater than 3999, then the expression ARABIC<4000 wil °
l''' °
'''return a zero, and the reduction 0/L0 will produce a null vector.'' °
' °
'''The APL2 interpreter ignores any branch to a null vector. Therefore °
''' °
'''the next expression to be evaluated will be the assignment of the'' °
' '''string ''''This number is too large'''' to U''' 'do' °
'show ''FN╜FN,Γ''''╕0''''''' °
'''A branch to zero is interpreted by APL2 as a command to EXIT the''' °
'''user defined function.''' 'do' °
'show ''FN╜FN,Γ''''L0:U╜RO 10 10 10 10ÿARABIC''''''' °
'''This expression is LABELLED. The label L0 is recognized by the''' °
'''presence of the colon (:). If the value of ARABIC is less than 4000 °
''' °
'''this expression will be evaluated, and the function will return the °
''' '''value of U.''' 'do' °
'''We now have completed the programming part. Let us take a look at'' °
' '''the array FN that we have just generated'',r' 'show ''πFN''' °
'''Before we can apply ÉFX, we could make sure that there is no APL2'' °
' °
'''object with that name. There is the System Function ÉNC for that''' °
'''purpose'',r' 'show ''ÉNC ''''ROMAN'''''' ''ÉNC ''''FN''''''' °
'''System Function ÉNC is called NAME CLASSIFICATION. It tells whether °
''' °
'''the right argument exists as an APL2 object. The 3 for ROMAN means' °
'' °
'''that ROMAN already exists as a function. The 2 for FN means that''' °
'''there is a variable called FN'',r' 'show ''ÉEX ''''ROMAN''''''' °
'''System function ÉEX (for EXPUNGE) has been applied to erase functio °
n''' °
'''ROMAN. The value 1 returned by ÉEX acknowledges successful erasure. °
'',r' °
'''It is good programming practice to apply ÉNC to a label, and then t °
o''' °
'''use ÉEX just before using ÉFX. (In APL2 ÉFX will override a previou °
sly''' '''defined function with the same name.)'',r' °
'show ''ÉNC ''''ROMAN''''''' °
'''The 0 returned by ÉNC ''''ROMAN'''' means that the label ROMAN is n °
ot in''' '''use.'',r' °
'show ''ÉFX FN'' ''ÉNC ''''ROMAN'''''' '' ROMAN 27 ''' °
'''Function ROMAN has been re-defined with FN, and works properly.''' °
'do' ''' DIAMOND SEPARATOR'',r' °
'''APL2 supports a notation called the "diamond separator". The symbol °
╪''' °
'''allows entering two or more expressions to be placed on a single li °
ne.''' '''The expressions are evaluated from left to right'',r' °
'show ''''''First line'''' ╪ ∞5 ╪ ''''Third line''''''' °
'''Using the diamond, we can re-define function ROMAN'',r' °
'FN╜''U╜ROMAN ARABIC''' °
'FN╜''U╜ROMAN ARABIC'' ''Σ To convert Arabic number to Roman notation' °
'' °
'FN╜FN,Γ''╕(ARABIC<4000)/L0 ╪ U╜''''This number is too large.'''' ╪ ╕0 °
''' 'FN╜πFN,Γ''L0:U╜RO 10 10 10 10ÿARABIC''' 'show ''FN'' ''ÉFX FN''' °
'''We have collapsed three lines into one. This technique is more than °
''' °
'''a device to reduce the number of APL lines in a function definition °
.''' °
'''As we will see later, it can be used to provide an important elemen °
t''' °
'''of structural programming. But now let us verify that the new versi °
Xon''' '''of ROMAN works properly'',r' 'show ''ROMAN 1997''' 'endd' °
*(1997 8 30 11 35 44 580) °
FTEACH4 ÉFX 'TEACH4;R;T;FN;MOVAVG' 'Σ Del mode' 'exit ''TEACH4''' °
'''Let us now describe the process of defining functions with the ╖''' °
'''symbol.'',r' °
'''WARNING! You will not be able to try out the examples on your own'' °
' °
''' until AFTER the lesson is completed. You may, however,''' °
''' use ÉFX to try out ideas of your own.''' 'do' °
'''We will try to define function MOVAVG. This function will evaluate' °
'' '''the moving average of a numeric vector or array. Here are two''' °
'''examples of the algorithm to be defined'',r' °
'show ''(3+/∞6)÷3'' ''(2+/2 4µ∞8)÷2''' °
'''We begin with the header. There are two arguments to this function: °
''' °
'''One is the data to be averaged, and the other is the averaging leng °
th.''' °
'''The function therefore should be dyadic. What we have to decide is' °
'' °
'''which should be the left argument, and which the right argument.''' °
'do' °
'''There are no hard and fast rules for deciding where arguments shoul °
d''' °
'''be placed. On the basis of past experience, and for other practical °
''' °
'''reasons, it is a good idea to place the data to be modified as the' °
'' '''right argument'',r' ''' ╖U╜L MOVAVG DATA''' '''[1]''' °
'FN╜''U╜L MOVAVG DATA'' ''Σ Moving average of length L on data''' °
'FN╜FN,''U╜L+/DATA'' ''U╜U÷L''' 'T╜ÉFX FN' 'do' °
'''The symbol ╖ preceeding the header expression is a toggle switch.'' °
' °
'''It transfers control to the APL2 function editor. At this point''' °
'''anything you enter at the terminal becomes part of the function''' °
'''under definition. You can always tell when you are in the APL2''' °
'''edit mode, because you are prompted by a line count'',r' °
'''[1] Σ Moving average of length L on DATA''' '''[2]''' 'do' °
'''Pressing ENTER terminates the line entry. A new prompt is issued''' °
'''for the next line'',r' '''[2] U╜L+/DATA''' '''[3] U╜U÷L╖''' 'do' °
'''Entering the symbol ╖ at the end of line 3 ends the function''' °
'''definition mode, as well as the process of definimg MOVAVG'',r' °
X 'show ''3 MOVAVG ∞6''' 'endd' °
*(1997 8 30 11 44 26 544) °
FTEACH5 ÉFX 'TEACH5;FN;T;MOVAVG' 'Σ Programming style' °
'exit ''TEACH5''' °
'FN╜''U╜L MOVAVG DATA'' ''Σ Running average of length L on data''' °
'FN╜FN,''U╜L+/DATA'' ''U╜U÷L''' 'T╜ÉFX FN' '''PROGRAMMING STYLES'',r' °
'''Before proceeding with further description of defined functions,''' °
'''it is apropriate at this point to make a few EDITORIAL remarks abou °
t''' °
'''programming style. Since programming is a highly personal effort''' °
'''there is always room for disagreement. Hence, in this and in later' °
'' °
'''sessions, my personal comments will be preceeded by the heading''' °
'do' '''''''PROGRAMMING STYLES''''.''' 'do' °
'''First, it should be clear that function MOVAVG has been designed''' °
'''merely to illustrate concepts in function definition. In practice'' °
' °
'''it does not make sense to write a special function, where a simple' °
'' °
'''line of code, namely (L+/DATA)÷L will suffice. One should therefore °
''' '''ask, why and when should one define an APL2 function.'',r' °
'''In my opinion there are three fundamental reasons for APL2 user def °
ined''' '''functions:'',r,r,'' 1. General utility functions''' °
''' 2. Problem solving functions'',r,'' 3. Subroutines'',r' °
'''Utility APL2 functions are those that one might want to use in many °
''' °
'''different applications. Problem solving functions are those that''' °
'''solve specific problems. An example of these would be function ROMA °
N.''' °
'''ROMAN uses functions RO and RX as subroutines. Defining RO and RX'' °
' °
'''as separate APL2 functions simplifies the code, and makes it easier °
''' '''to understand and to maintain.''' 'do' °
'''When defining utility functions, there are several considerations t °
o''' °
'''keep in mind. A utility has EDGE EFFECTS, DEFAULTS, and ABORTS.'',r °
' °
'''By edge effects, I mean special cases that one does not normally''' °
'''consider a solution to that particular utility. Let us assume that' °
'' '''we desire to treat function MOVAVG as a utility. Then'',r' °
'show ''1 MOVAVG ∞6'' ''6 MOVAVG ∞6''' °
'''The first expression returns the original argument unchanged, while °
''' '''the second expression returns the average.''' 'do' °
'''The main difference between the second expression, and AVERAGE ∞6'' °
' '''is in the rank of the result'',r' °
'show ''DISPLAY (+/∞6)÷6'' ''DISPLAY 6 MOVAVG ∞6''' °
'''These examples are not normally thought of as ''''moving averages'' °
'', but''' '''are acceptable.''' 'do' °
'''Consider now the following expressions'',r' °
'show ''DISPLAY 7 MOVAVG ∞6'' ''²2 MOVAVG ∞6''' °
'''While one could argue that these two examples are valid, it is not' °
'' '''likely one would consider the results as reasonable. Function''' °
'''MOVAVG, therefore, has some EDGE EFECTS that one might want to remo °
ve.''' 'do' °
'''Another problem is one of DEFAULTS. Suppose for the sake of argumen °
t''' °
'''that whenever we talk about moving averages, we normally assume tha °
t''' °
'''we are dealing with a specific value of the left argument, say 2.'' °
' °
'''Then it might be reasonable to request the omission of the left''' °
'''argument to signify a default value of 2. In other words whenever'' °
' '''one enters'',r,r,'' MOVAVG ∞6'',r' °
'''the result should be'',r,r,''1.5 2.5 3.5 4.5 5.5''' 'do' °
'''Finally, there may be expressions that cause the execution to be''' °
'''interrupted with an error message'',r' °
'show ''8 MOVAVG ∞6'' ''1.5 MOVAVG ∞6''' °
'''My personal approach in this situation is to avoid, or postpone''' °
'''the interrupt. For example, instead of the error message, the''' °
'''function prints on the screen a character string, such as'',r' °
''' You have entered an illegal argument in function MOVAVG'',r' °
'''and then returns a value that is clearly invalid (e.g. ∞0).''' °
'''Any subseqent handling of the result can be identified by the calli °
ng''' °
'''function, and remedial action be taken without an interrupt.''' °
'do' °
'''This is the end of my EDITORIAL COMMENT. I am well aware that this °
is''' °
'''NOT the approach taken by other APL users. Some feel strongly that' °
'' °
'''any improper invocation of a user defined function should cause an' °
'' °
'''interrupt and display an error message. Ultimately the decision on' °
'' °
'''how to deal with such edge effects, defaults and aborts will depend °
on''' '''who gets to use the final product.''' 'do' °
'''We will now see how these objectives can be achieved by refining th °
Xe''' '''function definition of MOVAVG.''' 'endd' °
*(1997 8 30 11 51 48 660) °
FTEACH6 ÉFX 'TEACH6;T;FN;MOVAVG' 'Σ Modifying a defined function' °
'exit ''TEACH6''' °
'FN╜''U╜L MOVAVG DATA'' ''Σ Moving average of length L on DATA''' °
'FN╜FN,''U╜L+/DATA'' ''U╜U÷L''' 'T╜ÉFX FN' °
'''Once a function has been defined, it is possible to re-enter the''' °
'''function definition mode with ╖MOVAVG[É]. This will produce a listi °
ng''' °
'''of the function, followed by a prompt to enter a new line'',r' °
'showfn ''MOVAVG''' '''[4]''' 'do' °
'''At this point additional lines can be added to the function. Since' °
'' °
'''we do not wish to add new lines following line [3], we can insert'' °
' '''lines by entering fractional line numbers'',r' '''[4] [1.1]''' °
'''[1.1] ╕(Lε∞²1╞µDATA)/L0''' °
'''[1.2] ''''You have entered an illegal argument in function MOVAVG'' °
'' ╪ U╜∞0 ╪ ╕0''' '''[1.3][2]''' '''[2] L0:U╜L+/DATA╖'',r' °
'T╜''''''You have entered an illegal argument in function MOVAVG'''' ╪ °
U╜∞0 ╪ ╕0''' 'FN╜(2╞FN),Γ''╕(Lε∞²1╞µDATA)/L0''' °
'FN╜FN,T ''L0:U╜L+/DATA'' ''U╜U÷L''' 'T╜ÉEX ''MOVAVG''' 'T╜ÉFX FN' °
'''We can now look at the modified function with ╖RUNAVG[É]╖''' °
'1 showfn ''MOVAVG''' °
'r,''The expression "╖MOVAVG[É]╖", beginning and ending with ╖ has the °
''' °
'''effect of entering the function definition mode, listing the functi °
on,''' °
'''and exiting the function definition mode. It is more useful than th °
e''' °
'''simpler ÉCR ''''MOVAVG'''' System Function in that it also provides °
the''' '''line numbering.''' 'do' °
'''The modified function MOVAVG now filters out invalid left arguments °
'',r' 'show ''²2 MOVAVG ∞6'' ''1.5 MOVAVG ∞6''' °
'''The next step is to allow MOVAVG to also support a monadic form.''' °
'''Whenever a function has that property, it is called AMBIVALENT.''' °
'''On a defined function, this can be done by testing whether the''' °
'''left argument is defined on entry to the function. This is done''' °
'''with the ÉNC System Function''' 'showfn ''MOVAVG''' '''[8]''' 'do' °
'''We will insert a test to that effect'',r' '''[8] [1.1]''' °
'''[1.1] ╕(2=ÉNC ''''L'''')/L1 ╪ L╜2''' °
'''[2] L1:╕(Lε∞²1╞µDATA)/L0╖''' °
'T╜(2╞FN),''╕(2=ÉNC ''''L'''')/L1 ╪ L╜2'' ''L1:╕(Lε∞²1╞µDATA)/L0''' °
'FN╜T,3╟FN' 'T╜ÉEX ''MOVAVG''' 'T╜ÉFX FN' 'do' °
'''Let us look at this new version. Note the usage of the diamond to d °
eal''' '''with the missing left argument'',r' '1 showfn ''MOVAVG''' °
'r,''Applying MOVAVG monadically, we get a default 2 for left argument °
X'',r' 'show ''2 MOVAVG ∞6'' ''MOVAVG ∞6''' 'endd' °
*(1997 6 17 13 4 55 448) °
FTEACH7 ÉFX 'TEACH7' 'Σ The session Manager editor' 'exit ''TEACH7''' °
''' THE SESSION MANAGER EDITOR'',r' °
'''Historically, the DEL (╖) editor is the oldest method of defining'' °
' '''APL functions. The Character Representation (ÉCR) was an early''' °
'''improvement that made it possible to store user defined functions'' °
' °
'''as character arrays in object libraries (See later tutorials dealin °
g''' '''with Auxilliary Processors 210 and 211.)'',r' °
'''The most recent development is an editor that is based on OS2. It i °
s''' °
'''called the Session Manager Editor. To invoke it, you simply press o °
n''' °
'''the EDIT pull down menu, and select "Open Object". A window will ap °
pear''' °
'''that is set to a user defined function default. It sets the prompt' °
'' °
'''in a box where you are expected to enter the name of the function.' °
'' °
'''However, if the function is already defined, you can save yourself °
the''' °
'''effort of typing it by scrolling down on the "Objects" box and clic °
king''' °
'''on the desired function name (That name will appear on the top box) °
'',r' °
'''At that point you can either double click on the name, or press the °
"OK"''' °
'''button. The session manager editor allows you to insert new lines, °
to''' °
'''change existing lines and to move text (to and from the current''' °
'''document or any other document accessible from OS2.)''' 'do' °
'''Note also the three buttons under the label "Type of Object". You c °
an''' °
'''switch between a character array or a function. (We will defer the' °
'' °
'''"Operator" option until such time this feature is discussed in a la °
ter''' °
'''tutorial session.) There is only one constraint. If a function has °
been''' °
'''defined, a character array cannot have that same name. Note also th °
at''' °
'''the Session Manager Editor can be used to create non-APL documents °
by''' °
'''taking advantage of the "COPY" and "PASTE" options in the pull down °
X''' '''editor.''' 'endd' °
*(1997 9 7 12 55 44 576) °
FTEACH8 ÉFX 'TEACH8;AVERAGE;T' 'Σ Headers' 'exit ''TEACH7''' °
'''We have seen examples of monadic and dyadic defined functions.''' °
'''We have also seen how a dyadic function can be made to behave as''' °
'''if it were monadic by making it ambivalent. Since the nature of''' °
'''arguments to a defined function is specified in the header, it is'' °
' '''only natural to ask what other headers are possible.''' 'do' °
'''There are two other variations to headers: First, headers need not' °
'' °
'''have any arguments. Function without arguments are called NILADIC.' °
',r' °
'''Niladic functions are typically used to provide explanations, or''' °
'''as main entries to applications. We will give specific examples in' °
'' '''future lessons of niladic functions.''' 'do' °
'''The other feature of headers deals with results. So far, our sample °
''' °
'''functions had a header of the form U╜... . Whenever a header contai °
ns''' °
'''such an assignment arrow, it is generally expected that the named'' °
' '''variable be generated in the body of the function before exit.''' °
'''Failure to do so will cause an error condition whenever an attempt' °
'' °
'''is made to assign the nonexistent result. (Some APL2 users will''' °
'''intentionally leave the result undefined to force an error whenever °
''' '''the function is used improperly.)'',r' °
'T╜ÉFX ''U╜AVERAGE R'' ''Σ Average of last dimension'' ''U╜+/R'' ''U╜Y °
÷0¥µR''' ''' ATTRIBUTES'',r' °
'''There is a System function that provides information about the''' °
'''ATTRIBUTES of a user defined function. ÉAT is dyadic. The left''' °
'''argument specifies the type of information to be retrieved. The''' °
'''right argument is the name (or array of names) to be searched.''' °
'''The attributes that can be obtained fall into 4 categories:'',r' °
''' 1 Valences (the nature of the headers of the function)''' °
''' 2 Time when the user defined function was last fixed''' °
''' 3 Whether the function is locked, displayable ....''' °
''' 4 Size of the character object (used with shared variables)'',r' °
'''Earlier we have defined function AVERAGE (it is re-defined here).'' °
,r' 'show ''ÉCR '''' AVERAGE ''''''' °
'''Let us look at its attributes:'',r' °
'show ''1 ÉAT ''''AVERAGE''''''' °
'''The vector 1 1 0 means the function produces a result (1), is monad °
ic''' '''(1) and is a function (0)'',r' °
'show ''2 ÉAT ''''AVERAGE''''''' °
'''The result gives the date and time when this function was fixed.'', °
r' 'show ''3 ÉAT ''''AVERAGE''''''' °
'''the vector indicates that this function is displayable, suspendable °
,''' °
'''interruptible, and displays non-resource errors. (These subjects wi °
ll''' °
'''not be extensively discussed in these introductory tutorials .)'',r °
' 'show ''4 ÉAT ''''AVERAGE''''''' °
'''The resulting vector indicates the function is a user defined funct °
Xion''' 'endd' °
*(1997 6 20 12 52 7 456) °
FTEACH9 ÉFX 'TEACH9;FN;TEST;TESTA;TESTB;TESTC;U;LEFT;RIGHT;T;F;G;H;I' °
'Σ Local variables' 'exit ''TEACH8''' °
'''LOCALIZATION OF VARIABLES'',r' °
'''In the header for function RUNAVG, there are four labels'',r' °
''' U L RUNAVG and DATA'',r' °
'''The labels U L and DATA are reserved names of variables. All header °
''' °
'''labels in a defined function have a SCOPE and a STATUS. The scope c °
an be''' °
'''LOCAL or GLOBAL, and the status can be DEFINED or UNDEFINED. Let us °
''' '''now study these concepts.''' 'do' °
'''Let us investigate a defined function we shall call TESTA'',r' °
'show ''FN╜''''LEFT TESTA RIGHT'''' ''''DISPLAY LEFT RIGHT G'''' ''''G °
╜''''''''global''''''''''''''' 'show ''ÉFX FN''' °
'''Let us first assign values to LEFT RIGHT and G'',r' °
'show ''(LEFT RIGHT G)╜''''SIX'''' ''''SEVEN'''' ''''GLOBAL'''''' ''DI °
SPLAY LEFT RIGHT G''' '1 showfn ''TESTA''' '''''' °
'show ''6 TESTA 7'' ''DISPLAY LEFT RIGHT G''' °
'''Within function TESTA the "value" of LEFT and RIGHT is 6 and 7 resp °
ectively.''' °
'''The "value" of G remains ''''GLOBAL'''' because G is not listed in °
the header''' °
'''of TESTA. On exit from function TESTA the value of variables LEFT a °
nd''' °
'''RIGHT reverts to their global setting. By re-defining G within func °
tion''' '''TESTA, we changed its content in the global variable G.''' °
'do' °
'''Any variables not specified in the header of a function are called °
global.''' °
'''Any global variable having the same name as a variable in a header °
of a''' '''function cannot be reached from within that function.'',r' °
'''Suppose now, we wish to define an additional label in a function, s °
o that''' °
'''it too is local. APL2 supports such a localization in the header'', °
r' °
'FN╜''TESTB;F G H I'' ''I╜π,■''''FGHI'''''' ''DISPLAY I'' ''ÉNC I'' '' °
H╜4''' 'show ''πFN''' °
'''We have defined a NILADIC function named TESTB. The header includes °
a''' °
'''semicolon followed by a list of labels (F G H and I). These now def °
ine''' '''APL2 objects that are strictly local to TESTB.''' °
'''(Note that ÉNC accepts rank 2 character arrays of labels)'',r' °
'do' 'FN╜FN,''G╜''''U╜F H'''' ''''U╜∞H'''''' ''ÉFX G'' ''F H''' °
'show ''πFN''' °
'''We have added three more lines to function TESTB. Variable G become °
s a''' °
'''nested vector defining F as a monadic function with argument H. Nex °
t,''' °
'''G is fixed defining function F. F becomes a function local to TESTB °
.''' '''The final line of function TESTB evaluates function F.'',r' °
'show ''ÉFX FN''' '1 showfn ''TESTB''' °
'''Before we proceed with the evaluation of TESTB, you want to study'' °
' '''carefully the listing of function TESTB.''' 'do' °
'''Before we evaluate TESTB, we will also define GLOBAL variables F, G °
,''' '''H and I'',r' °
'show ''(F G H I)╜''''ONE'''' ''''TWO'''' ''''THREE'''' ''''FOUR'''''' °
''DISPLAY F G H I''' 'show ''TESTB'' ''πF G H I''' °
'''In summary, the header can be used to define not only the nature of °
''' °
'''the function (monadic, dyadic, niladic and with or without result), °
''' °
'''but also any labels that are to be stricly local to that function.' °
'' °
'''These localized object names can be used to define any valid APL2'' °
' '''objects.''' 'do' °
'''Before we leave the subject of headers, there is one other aspect'' °
' °
'''of its use. When the APL2 interpreter reads the header in order to' °
'' °
'''allocate and match arguments to names, it does so from left to righ °
t'',r' °
'show ''ÉFX ''''U╜U TESTC U'''' ''''U'''' ''''U╜0'''''' ''5 TESTC ∞4'' °
' °
'''In the header, the label repeats 3 times. As the header is evaluate °
d,''' °
'''the leftmost argument, the asigned variable is left undefined. Then °
''' °
'''the left argument of TESTC, if present is assigned to U. Finally th °
e''' °
'''right argument of TEST is assigned to U. Knowing this sequence allo °
ws''' '''definition of default results in some applications'',r' °
'show ''ÉFX ''''R╜L TEST R'''' ''''╕(0=ÉNC ''''''''L'''''''')/0'''' '' °
''R╜R+L''''''' 'show ''ÉCR ''''TEST'''''' ''3 TEST 4'' ''TEST 5''' °
X '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 16 12 11 1 260) °
Ferase ÉFX 'erase;t;EXIT;GO;HELP;BIND;DISPLAY;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' °
*(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 5 22 276) °
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' °