home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH12A.ATF
< prev
next >
Wrap
Text File
|
1997-09-19
|
48KB
|
581 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 °
XAA╜(1)(2 3)('TEXT') °
*(1996 4 6 16 7 6 220) °
XFAND ÉFX 'Z╜(f AND g)R' 'Z╜(f R)(g R)' °
*(1996 4 6 16 7 6 220) °
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 7 6 220) °
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 7 7 224) °
FEACHLEAF ÉFX 'U╜V(f EACHLEAF)W' 'Σ Apply f to each leaf of W' °
X '╕(V<╧W)/L0' 'U╜f■W' '╕0' 'L0:U╜V f EACHLEAF■W' °
*(1996 4 6 16 7 6 220) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1996 4 6 16 7 6 220) °
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 30 6 356) °
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╜5),'' 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 the previous lesson''' 'endd' °
*(1997 8 17 11 31 45 516) °
FHEXMATH ÉFX 'U╜V(f HEXMATH)W' 'Σ Hexadecimal integer arithmetic' °
'╕(0=ÉNC ''V'')/MON ╪ U╜DtoH(HtoD V)f HtoD W ╪ ╕0' °
X 'MON:U╜DtoH f HtoD W' °
*(1996 4 6 16 7 7 224) °
XFNEW1 ÉFX 'U╜L(f NEW1 g)R' 'Σ New operator' 'U╜(L f R)L g R' °
*(1996 4 6 16 7 7 224) °
FREDUCE ÉFX 'U╜(f REDUCE)W' 'Σ Reduce nested scalars' '╕(0≤µW)/L0' °
X '╕(0=╧U╜W)/0' 'U╜Γf REDUCEπW' '╕0' 'L0:U╜f/W' °
*(1996 4 6 16 7 6 220) °
FREVIEW ÉFX 'REVIEW' 'Σ Review of user defined functions' °
'''We learned that there are two ways for the APL2 user to define''' °
'''functions. One way is to use the ÉFX System function, and the other °
''' °
'''is to use is to use the symbol ╖ to signal a switch to and from the °
''' °
'''function definition mode. (In commercial versions there are yet oth °
er''' '''techniques based on the use of EDITORS.)'',r' °
'''A defined function consists of one HEADER line, followed by one or' °
'' °
'''more valid APL2 expressions. The header line describes to the APL2' °
'' °
'''interpreter the nature of the defined function (monadic, dyadic,''' °
'''niladic and with or without a result; it also defines local labels. °
)''' 'do' °
'''The body of the defined function is normally evaluated in the seque °
nce''' °
'''of the expressions. This sequence can be altered with the usage of' °
'' °
'''the right arrow ╕. Whenever this arrow ocurrs, it is possible to ma °
ke''' °
'''a choice between branching to a line (or exit) or to continue in th °
Xe''' '''normal sequence.''' 'endd' °
*(1997 7 4 12 22 55 468) °
FTEACH ÉFX 'TEACH' 'Σ Start lesson 12: APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' 'TEACH1 Σ Outer product operator' °
'TEACH2 Σ User defined operators' °
'TEACH3 Σ Examples of user defined operators' °
'TEACH4 Σ More examples' °
X 'TEACH5 Σ Locked functions; quad fix with left argument' 'problems' °
*(1997 6 20 13 10 27 372) °
FTEACH1 ÉFX 'TEACH1;FN;PRIME;T' 'Σ Outer product operator' °
'''To review the previous lesson, enter REVIEW.'',r' °
'''In this lesson we will study user defined OPERATORS. However before °
''' °
'''we get into that subject, we must complete our study of the dot''' °
'''operator. As we learn more about this operator, we will practice th °
e''' '''newly acquired skills for defining APL2 functions.''' 'do' °
'''In lesson 10 we studied the dot as an operator taking a left and a' °
'' °
'''right argument function. We named this the inner product, because'' °
' °
'''regardless of the function used, the result reduced the combined''' °
'''rank of the two arguments.'',r' °
'''There is another usage of the dot operator. It is possible to''' °
'''replace the left argument FUNCTION by the special symbol called the °
''' °
'''JOT (°). Any expression containing the string °.f (where f is any'' °
' °
'''function) is called the OUTER PRODUCT. The rank of the result of''' °
'''using °.f is the sum of the ranks of the two arguments'',r' °
'show ''DISPLAY (∞5)°.⌡∞5''' °
'''In this example we applied the ⌡ function to two vectors, and got'' °
' '''a multiplication table. The function need not be pervasive'',r' °
'show ''DISPLAY (∞2)°.,∞2''' °
'''To illustrate how one might want to use this operator, consider the °
''' °
'''problem of generating a sequence of prime numbers. Let us assume''' °
'''that we wish to define function PRIME.'',r' °
'''NOTE: There are far more efficient methods for computing prime''' °
''' numbers. Function PRIME is used here solely to illustrate''' °
''' the usage of the outer product and to refresh your memory''' °
''' of modulo arithmetic.'',r' 'do' °
'show ''FN╜''''U╜FROM PRIME TO;T;P;R'''' ''''Σ Find primes from 1+FROM °
to TO''''''' '''We can begin with the first 18 primes'',r' °
'show ''FN╜FN,Γ''''T╜2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 °
''''''' °
'show ''FN╜FN,''''U╜((T≤TO)^T>FROM)/T'''' ''''╕(61≥TO)/0''''''' °
'''Note that T>FROM specifically excludes the value of FROM if prime.' °
',r' 'show ''ÉFX FN'' ''11 PRIME 17''' '1╟1 showfn ''PRIME''' °
'''If the value of TO is 61 or smaller, then we are done. Else, we hav °
e''' '''some more work to do.''' 'do' °
'''First we have to define some auxilliary local variables:'',r' °
'show ''FN╜FN,''''FROM╜FROM-0=2|FROM'''' ''''R╜⌐TO*.5''''''' °
'''It will be convenient to insure that the value of FROM is odd. Then °
''' °
'''if a number N in the range of (FROM to TO) is not a prime, it will °
be''' °
'''of the form A⌡B. Le us assume that A<B. Then N will be prime if it °
is''' '''NOT divisible by any integer in the range 2 to R≤N*0.5.'',r' °
'show ''FN╜FN,''''FROM╜FROM⌐61'''' ''''P╜FROM+2⌡∞⌐(TO-FROM)÷2''''''' °
'''There is no need to re-generate primes in the range 2 to 61.''' °
'''We generate vector P of all odd numbers in the desired range.'',r' °
'show ''FN╜FN,''''U╜U,(^≡0⌠(1╟T)°.|P)≡P'''' ''''╕(R≤0¥T)/0''''''' °
'''The first expression uses the outer product with the residue functi °
on.''' °
'''Only those values of P will be retained that do not leave a residue °
of''' °
'''zero when divided by integers of 1╟T. (since values of P are all od °
d,''' '''there is no need to test for division by 2.)''' 'do' °
'show ''ÉFX FN'' ''103 PRIME 147''' '1╟1 showfn ''PRIME''' °
'''This will work for integers less than (61*2) or 3721. For larger''' °
'''integers we have still more work to do'',r' °
'''There may be integers in the vector U that are divisible by an''' °
'''integer greater than ⌐/T'',r' °
'show ''FN╜FN,''''T╜(0¥T) PRIME R'''' ''''U╜(^≡0⌠T°.|U)≡U'''''' ''ÉFX °
FN''' °
'''First we generate a new vector T of greater primes that have not ye °
t''' °
'''been tested. Then we apply the outer product of residues to T and U °
,''' '''and remove all integers in U divisible by T'',r' °
'1╟1 showfn ''PRIME''' °
'''This will work as long as there is sufficient free space in memory' °
'' °
'''to generate the outer product. If the vectors U and R are too long' °
'' '''there may have to be yet more to this function.'',r' °
X 'show ''9000 PRIME 9100''' 'endd' °
*(1997 8 31 12 54 43 660) °
FTEACH2 ÉFX 'TEACH2;PLUS;REDUCE;FN;OP;TEST;NV' °
'Σ User defined operators' '''USER DEFINED OPERATORS'',r' °
'''We already know how to define an APL2 function that will mimick a'' °
' '''primitive function. Here is an example'',r' °
'show ''ÉFX ''''U╜V PLUS W'''' ''''U╜V+W'''''' ''3 PLUS ∞4''' °
'''In APL2 it is possible to also define an operator in a similar way' °
',r' °
'show ''ÉFX ''''U╜(f REDUCE) W'''' ''''ΣReduction operator'''' ''''U╜f °
/W''''''' °
'''The parentheses are required in the header for two reasons:'',r' °
''' 1. To indicate that the APL2 object being defined is''' °
''' an operator, and not a function.''' °
''' 2. To show the strong binding between the function and''' °
''' the defined operator.''' 'do' '1 showfn ''REDUCE''' °
'''The f in parentheses is called the OPERAND. It represents any valid °
''' °
'''primitive or defined function. Operator REDUCE is monadic with resp °
ect''' °
'''to its operand and monadic with respect to its argument (W). Note t °
hat''' °
'''for a monadic operator, the operand appears to the LEFT, and the''' °
'''argument appears to the RIGHT. (Enter BIND to review binding rules) °
'',r' °
'''Any user defined function can be applied to an APL2 operator, provi °
ded''' °
'''the expression is a valid one. Also, when a defined operator is inv °
oked,''' '''the parentheses of the header are not required'',r' °
'show ''+/∞5'' ''PLUS/∞5'' ''+REDUCE ∞5'' ''PLUS REDUCE ∞5''' °
'''It is therefore possible to define a set of functions and operators °
''' °
'''so that none of the special APL2 symbols need be used. This would b °
e''' °
'''useful in situations where the user has no access to an APL font.'' °
,r' 'do' °
'''The most general format of the header of a defined operator is'',r' °
''' RESULT╜LEFTARG (leftfn OPNAME rightfn) RIGHTARG'',r' °
'''In this most general case, the operator is dyadic in its operands, °
and''' °
'''dyadic in its arguments. The left argument (LEFTARG) of a defined'' °
' °
'''operator can be made to be optional (ambivalent OPERATOR in its lef °
t''' °
'''argument). The right operand however, when present in the header,'' °
' '''cannot be made ambivalent.''' 'do' °
'show ''OP╜''''U╜L (f TEST g) R'''' ''''╕(2=ÉNC ''''''''L'''''''')/L0 °
╪ L╜∞µR''''''' 'show ''OP╜OP,Γ''''L0:U╜L f.g R'''''' ''ÉFX OP''' °
'1 showfn ''TEST''' °
'''Notice that in line [2] f.g is separated from L and R by a blank.'' °
,r' 'show ''1 2+TEST⌡3 5'' ''+TEST⌡3 5''' 'do' °
'''There are two types of applications for defined operators:'',r' °
''' 1. Extensions to existing operators''' °
''' 2. Creation of entirely new operator types'',r' °
'''Let us explore first extensions to existing operators.''' 'do' °
'''Before we describe examples of extensions to defined operators, it' °
'' °
'''should be noted that all operators (except EACH) imply a dyadic''' °
'''function. Suppose now that we wish to extend an operator, say''' °
'''reduction, to handle a scalar right argument of depth greater than °
2'',r' °
'show ''OP╜''''U╜(f REDUCE) W'''' ''''Σ Reduce nested scalars'''' '''' °
╕(0≤µW)/L0''''''' °
'''First we test whether the argument is of RANK 0.''' °
'''If it is not, branch to expression L0 with primitive reduction''' °
'''operator. Else we have to enclose the reduction of the disclose'',r °
' °
'show ''OP╜OP,''''╕(0=╧U╜W)/0 ╪ U╜Γf REDUCE■ πW ╪ ╕0'''' ''''L0:U╜f/W' °
'''''' °
'''If the scalar has depth of zero, REDUCE returns the right argument. °
''' °
'''Else the reduction will be applied to the disclose of the argument, °
''' '''and the result will be enclosed.'',r' 'show ''ÉFX OP''' °
'1 showfn ''REDUCE''' °
'show ''⌡REDUCE 5'' ''DISPLAY ÷/(10 6) (2 3)'' ''DISPLAY ÷REDUCE (10 6 °
) (2 3)''' °
'show ''-/4 1'' ''-REDUCE 4 1'' ''NV╜Γ((1 2) (3 4)) (5 6)''' °
'show ''+/NV'' ''PLUS REDUCE NV''' °
'''FOOTNOTE: The current version of APL2 does not produce a valid''' °
''' result when the right argument is a null vector.'',r' °
X 'show ''^/∞0'' ''^REDUCE ∞0''' 'endd' °
*(1997 8 31 12 59 42 676) °
FTEACH3 ÉFX 'TEACH3;OP;EACHLEAF;T;HtoD;DtoH;AND' °
'Σ Operator extensions on monadic functions' °
'''Earlier it was pointed out that the each operator was the only one' °
'' °
'''that can be applied to a monadic function. Let us develop an extens °
ion''' °
'''to a defined operator that works on monadic functions. (This exampl °
e''' '''was brought to my attention by Roy Sykes.)'',r' °
'OP╜''U╜V (f EACHLEAF) W'' ''Σ Apply f to each leaf of W''' °
'OP╜OP,''╕(V<╧W)/L0 ╪ U╜f■W ╪ ╕0'' ''L0:U╜V f EACHLEAF■ W''' °
'T╜ÉFX OP' °
'''This defined operator generalizes the use of the each operator''' °
'1 showfn ''EACHLEAF''' °
'''If the right argument has a depth greater than that given by the le °
ft''' °
'''argument, the application of the function is delayed for the inner' °
'' °
'''elements of the array. Else the monadic function is applied.'',r' °
'show ''DISPLAY µ■(1(2(3 4)))'' ''DISPLAY 3 µEACHLEAF (1(2(3 4)))''' °
'show ''DISPLAY µ■■(1(2(3 4)))'' ''DISPLAY 2 µEACHLEAF (1(2(3 4)))''' °
'''Here is another example of using EACHLEAF. Function ∞ requires its' °
'' '''right argument to be a scalar integer'',r' °
'show ''DISPLAY 0 ∞EACHLEAF (2 (3 4))''' ''' NEW OPERATORS'',r' °
'''Let us now consider examples of operators that are not available in °
''' °
'''APL2. Why should we want to do that in the first place, and under w °
hat''' '''conditions would this be useful?''' 'do' °
'''Since an operator is used to modify a function to produce a DERIVED °
''' °
'''function, there may be situations where a certain activity is desir °
ed''' '''regardless of the applied function.'',r' °
'''What a defined operator allows us to do is to DELAY BINDING until t °
he''' °
'''time of invocation of the function. The simplest example of this is °
''' '''the favorite one of Ray Polivka''' °
'T╜ÉFX ''U╜(f AND g) W'' ''Σ Catenate functions'' ''U╜(f W) (g W)''' °
'1 showfn ''AND''' '''Here is how Ray would use this operator'',r' °
'show ''A╜(1(2 3)''''TEXT'''')'' ''µ AND ╧A'' ''µ AND ╧ AND DISPLAY A' °
'' '''Here is another example:''' °
'''Consider other than decimal number systems. In the hexa-decimal''' °
'''notation, we use the letters A,B,C,D,E and F to denote the integers °
''' °
'''10, 11, 12, 13, 14 and 15. Hexa-decimal 15, for example stands for' °
'' °
'''decimal 21 (since it is equal to decimal 16 + 5). We could therefor °
e''' '''define an operator to do Hexa-decimal arithmetic.''' 'do' °
'''Before we can do that, we have to define two functions: DtoH and Ht °
oD''' 'OP╜''U╜DtoH W'' ''Σ Convert decimal integers to hexadecimal''' °
'T╜ÉFX OP,Γ''U╜''''0123456789ABCDEF''''[1+((1+╛16╡W)µ16)ÿW]''' °
'1 showfn ''DtoH''' °
'OP╜''U╜HtoD W'' ''Σ Convert hexadecimal strings to decimals''' °
'T╜ÉFX OP,Γ''U╜16¥²1+''''0123456789ABCDEF''''∞W''' °
'1 showfn ''HtoD''' '''We should verify these functions first'',r' °
'show ''DtoH 256'' ''HtoD ''''100'''''' ''DtoH 255'' ''HtoD ''''FF'''' °
''' '''Now we can define function HEXMATH'',r' °
'OP╜''U╜V (f HEXMATH) W'' ''Σ Hexadecimal integer arithmetic''' °
'OP╜OP,Γ''╕(0=ÉNC ''''V'''')/MON ╪ U╜DtoH (HtoD V) f HtoD W ╪ ╕0''' °
'T╜ÉFX OP,Γ''MON:U╜DtoH f HtoD W''' '1 showfn ''HEXMATH''' °
'''Line [2] deals with dyadic expressions, while line [3] handles mona °
dic''' '''ones. Let us see how this function works'',r' °
'show ''''''1'''' +HEXMATH ''''FF'''''' ''''''ABC'''' ⌡HEXMATH ''''CBA °
''''''' '''and to verify this last expression'',r' °
'show ''''''889C98''''╧DtoH (HtoD ''''ABC'''')⌡HtoD ''''CBA''''''' °
X 'endd' °
*(1997 6 21 12 26 42 496) °
FTEACH4 ÉFX 'TEACH4;NEW;NEW1;T' °
'Σ Dyadic defined operator with two functions' °
'''When defining a new operator you should at first proceed with much' °
'' °
'''caution. It is important to analyze the binding of all expressions. °
''' 'do' °
'''Here is an example of a new dyadic operator using two functions as' °
'' '''an argument''' °
'T╜ÉFX ''U╜L (f NEW g) R'' ''Σ New operator'' ''U╜(L f R) (L g R)''' °
'1 showfn ''NEW''' °
'show ''5 +NEW- 3'' ''DISPLAY (1 (2 3)) +NEW⌡ 5 (6 2)''' °
'''We will now re-define a similar operator, but with one very minor'' °
' °
'''change. (Such a change would have no effect on a defined function.) °
''' °
'T╜ÉFX ''U╜L (f NEW1 g) R'' ''Σ Another operator'' ''U╜(L f R) L g R'' °
' '1 showfn ''NEW1''' °
'''The only difference is in the missing parentheses on the dyadic''' °
'''function g'',r' 'show ''5 +NEW1- 3''' °
'''Let us analyze what happens. First let us look at binding rules:'', °
r' 'BIND' 'do' °
'''Why does 5 +NEW1- 3 produce 5 2? Let us look at the expression'',r' °
''' (L f R) L g R'',r' °
'''BY binding rule 3, the g is bound to R and then the f is bound to R °
.''' °
'''Then by rule 4. (L f R) L is bound as a vector. Finally by rule 5'' °
' °
'''the two element vector (L f R) L is bound to g. We therefore evalua °
te'',r' 'show ''5 + 3'' ''8 5 - 3''' °
'''As an exercise, you should go through the process of evaluation''' °
'''of the expression: (1 (2 3)) +NEW1⌡ (5 (6 2))'',r' °
X 'show ''DISPLAY (1 (2 3)) +NEW1⌡ 5 (6 2)''' 'endd' °
*(1997 6 21 12 32 57 580) °
FTEACH5 ÉFX 'TEACH5;FOO' 'Σ Locked functions' °
'''If you use APL2 for commercial applications, you may wish to keep'' °
' '''your algorithms secret. APL2 provides a feature that in effect''' °
'''prevents a defined function (or operator) from being displayed.''' °
'''One way to do it is to use the symbol ·. This symbol is a toggle''' °
'''switch similar to ╖, except that the defined function becomes''' °
'''LOCKED. Once locked it is extremely difficult to reveal its''' °
'''internal algorithm.'',r' °
'''When a function is defined with the · symbol, it is a good idea to' °
'' '''have an unlocked copy in a separate workspace.''' 'do' °
'''There is another way to lock defined functions. The ÉFX System''' °
'''Function can be used with a left argument'',r' °
'show ''0 0 0 0 ÉFX ''''U╜FOO W'''' ''''U╜∞W'''''' ''ÉCR ''''FOO'''''' °
''FOO 5''' °
'''In the above example, the vector of zeros is equivalent to not''' °
'''having a left argument. However a 1 in any one of these positions'' °
' '''will have as an effect a restriction on the defined function'',r' °
'show ''1 0 0 0 ÉFX ''''U╜FOO W'''' ''''U╜∞W'''''' ''ÉCR ''''FOO'''''' °
''FOO 5''' °
'''Even though function FOO exists and works, it cannot be displayed.' °
'' '''A 1 in the other positions deals with the ability to suspend,''' °
'''interrupt and produce error messages. If this subject is of interes °
Xt,''' '''you should consult the appropriate manuals.''' 'endd' °
*(1996 4 6 16 7 7 224) °
XFTEST ÉFX 'U╜L(f TEST g)R' '╕(2=ÉNC ''L'')/L0' 'L╜∞µR' 'L0:U╜Lf.gR' °
*(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 27 25 420) °
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' °
*(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 7 6 220) °
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' °