home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH8A.ATF
< prev
next >
Wrap
Text File
|
1997-09-18
|
76KB
|
933 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 °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1996 4 6 16 3 42 348) °
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 3 42 348) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1996 4 6 16 3 42 348) °
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 15 12 29 26 428) °
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╜7),'' 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 contents of the preceeding lesson''' 'endd' °
XAP╜0µΓ0 0 °
*(1997 5 29 12 58 21 568) °
FREVIEW ÉFX 'REVIEW' 'Σ Review lesson 7 on depth' °
'''APL2 supports a wide diversity of data structures. The mechanism''' °
'''for this is called nesting. We have seen in lesson 6 that data can' °
'' '''be organized into rectangular arrangements called arrays. The''' °
'''elements of these arrays are scalars (or rank 0 arrays).''' 'do' °
'''Simple scalars were defined to be numbers or single characters. As °
an''' °
'''extension of the concept of a scalar, APL2 supports a process calle °
d''' °
'''ENCLOSE, that converts arbitrary data structures into objects that' °
'' °
'''have all the properties of a scalar. With this extension it is now' °
'' '''possible to generate data structures of arbitrary complexity.''' °
'do' °
'''To support the manipulation of nested data structures, it is necess °
ary''' °
'''to supply primitive functions. Three of these primitive functions w °
ere''' °
'''introduced in lesson 7. Depth (╧) is a monadic function that return °
s''' '''the amount of nesting in a data structure'',r' °
'show ''DISPLAY ((1 2) (3 4)) (5 6) 7'' ''╧((1 2) (3 4)) (5 6) 7''' °
'''The enclose (with or without axis specification) is a monadic primi °
tive''' '''function that increases the depth of a structure'',r' °
'show ''DISPLAY 2 2µ∞4'' ''DISPLAY Γ2 2µ∞4'' ''DISPLAY Γ[1]2 2µ∞4''' °
'''The monadic disclose is a primitive APL2 function that removes one' °
'' '''level of nesting from a data structure'',r' °
'show ''DISPLAY (1 2) (3 4)'' ''DISPLAY π(1 2) (3 4)''' °
'''When the data has a depth of one or less, disclose has no effect.'' °
' °
'show ''DISPLAY 2 2µ∞4'' ''DISPLAY π2 2µ∞4'' ''DISPLAY ,5'' ''DISPLAY °
π,5''' °
'''Both the enclose and the disclose symbols exist as dyadic primitive °
''' °
'''functions. The dyadic disclose is called PICK. It allows the extrac °
tion''' °
'''of the contents of a nested structure. The left argument is a vecto °
r''' °
'''called ACCESS VECTOR. Its elements must be valid access vectors'',r °
' °
'show ''DISPLAY 1 (2 2µ1 2 (3 4 5) 6) 7'' ''2 (2 1) 3π1 (2 2µ1 2 (3 4 °
5) 6) 7''' °
'''The dyadic enclose is called PARTITION. The left argument is an int °
eger''' °
'''vector of the same length as the vector right argument. A zero in t °
he''' °
'''left argument is allowed, and acts to suppress the corresponding ri °
ght''' °
'''argument element. The boundaries where the left argument increases' °
'' '''become the boundaries of nesting'',r' °
'show ''TEXT╜''''ONE TWO THREE'''''' ''DISPLAY TEXT'' ''DISPLAY (TEXT⌠ °
X'''' '''')ΓTEXT''' 'endd' °
*(1997 5 31 11 59 20 572) °
FRULE ÉFX 'V RULE W' 'Σ Display rules' '╕(2=ÉNC ''V'')/L0' °
X '2 rule W ╪ ╕0' 'L0:V rule W' °
*(1997 7 4 11 53 15 428) °
FTEACH ÉFX 'TEACH' 'Σ Start eight lesson in APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' °
'TEACH1 Σ Take and drop; fill elements and prototypes' °
'TEACH2 Σ Take and drop with axis specification' 'TEACH3 Σ First' °
'TEACH4 Σ Enlist and text processing' °
'TEACH5 Σ More on enlist and ravel' °
'TEACH6 Σ Catenation of arrays; lamination' °
X 'TEACH7 Σ Reverse, rotate and transpose' 'problems' °
*(1997 6 5 13 37 50 512) °
FTEACH1 ÉFX 'TEACH1' 'Σ Processing nested data structures' °
'exit ''TEACH1''' °
'''As before, you may review previous lesson by entering REVIEW.''' °
'do' °
'''In this lesson we will concentrate on those features of APL2 that'' °
' °
'''will support every possible manipulation of data structures. We alr °
eady''' °
'''know how to generate data with a great deal of complexity. We now n °
eed''' '''some more tools in our toolbox.'',r' °
'''We will begin with two new primitive dyadic functions called TAKE a °
nd''' '''DROP. Let us see first how these functions work on vectors''' °
'do' °
'''The Take function does what it''''s name implies. It takes from the °
right''' °
'''argument the number of elements specified by its left argument'',r' °
'show ''DISPLAY 2╞(1 2) (3 4) (5 6)''' °
'''For a vector right argument, the left argument should be a vector o °
f''' °
'''length one. However a scalar will work as well, but this is the onl °
y''' °
'''exception. The right argument vector can contain arbitrary data''' °
'''structures. When the left argument integer is positive, the right h °
and''' °
'''components are taken from left to right. When the left argument''' °
'''negative, the components are taken from right to left'',r' °
'show ''DISPLAY ²2╞(1 2) (3 4) (5 6)''' °
'''The left argument also allows a zero value'',r' °
'show ''DISPLAY 0╞(1 2) (3 4) (5 6)''' °
'''The result of this expression is an empty array, but one that conta °
ins''' '''a vector of two FILL ITEMS.''' 'do' °
''' FILL ELEMENTS AND PROTOTYPES'',r' °
'''Let us experiment with this some more'',r' °
'show ''DISPLAY 0╞''''AB'''' ''''CD'''''' ''DISPLAY 0╞(1 2) ''''AB'''' °
''' °
'''In the first example, the fill elements are two blanks. In the seco °
nd''' °
'''example the fill elements are two zeros. Clearly the fill elements' °
'' °
'''are taken from the pattern of the first element of the right argume °
nt.''' 'do' °
'''If this is true, then the structure of the vector past the first''' °
'''element should be immaterial. Let us see if this happens'',r' °
'show ''DISPLAY 0╞(1 2) (3 (4 5)) 6''' °
'''The vector inside the empty box is a kind of generalized FILL eleme °
nt.''' °
'''It is called a PROTOTYPE. Why is this concept important? Consider t °
he''' '''following two expressions'',r' °
'show ''DISPLAY 5µ(1 2) (3 4) (5 6)'' ''DISPLAY 5╞(1 2) (3 4) (5 6)''' °
'''In the first expression a vector is shaped by taking the elements'' °
' °
'''of the right argument from left to right in cyclic order. In the''' °
'''second expression when more elements are asked for than there are'' °
' '''in the right argument, these are filled in by prototypes.''' 'do' °
'''What will we get if we use negative integers in the left argument?' °
',r' 'show ''DISPLAY ²5╞(1 2) 3 4''' °
'''Clearly we get the same prototype as the fill element.''' 'do' °
'''So far we have applied the Take function to nested vectors. What''' °
'''about rank 0 arrays and arrays of rank 2 and greater?'',r' °
'show ''DISPLAY 3╞Γ(1 2) 3'' ''DISPLAY 2 4╞3 3µ∞9''' °
'''The Take of a rank 0 array will generate a vector with prototypes i °
n all''' °
'''but the first element. The Take of a rank 2 array requires the left °
argument''' °
'''to be a vector of length 2. More generally, the length of the left' °
'' '''argument must be the same as the rank of the right argument.''' °
'do' °
'''The left argument axis specification can have negative integers'',r °
' 'show ''DISPLAY 2 ²4╞3 3µ∞9'' ''DISPLAY ²2 4╞3 3µ∞9''' °
'''What will a zero do in the left argument of Take for arrays?'',r' °
'show ''DISPLAY 2 2µ(1 2) 3 ''''AB'''''' ''DISPLAY 0 3╞2 2µ(1 2) 3 ''' °
'AB''''''' °
'''Note that even in a rank 2 array, the prototype is determined from °
the''' '''first element of the first row.''' 'do' °
'''DROP is a dyadic APL2 primitive complementary to Take'',r' °
'show ''DISPLAY 2╟(1 2) (3 4) (5 6)'' ''DISPLAY ²3╟(1 2) (3 4) 5 6 7'' °
' °
'''Since Drop removes elements from an array, the prototype enters the °
''' '''picture when nothing is left after the Drop'',r' °
'show ''DISPLAY 2╟(1 2) (3 4)'' ''DISPLAY 100╟(1 2) (3 4)''' °
'''For arrays Drop works the same way as for Take'',r' °
'show ''2 2╟4 4µ∞16'' ''2 ²3╟4 4µ∞16''' °
'''We can summarize our finding about Take and Drop'',r' '0 RULE 30' °
X 'endd' °
*(1997 6 5 13 38 17 384) °
FTEACH2 ÉFX 'TEACH2;A;B' 'Σ First and drop and take with axis' °
'exit ''TEACH2''' ''' TAKE AND DROP WITH AXIS SPECIFICATION'',r' °
'''Both Take and Drop allow axis specification. For an array, any axis °
''' °
'''may be specified. Axes not specified will be left unchanged.'',r' °
'show ''DISPLAY 2╞∞9'' ''DISPLAY ²2╞[1]∞9''' °
'''Although the axis specification clearly works for a vector, it does °
''' °
'''not appear to be of any practical import. For arrays, we have'',r' °
'show ''DISPLAY ²2 3╞3 3µ∞9'' ''DISPLAY ²2╞[1]3 3µ∞9''' °
'''For the Drop, the analogous expressions are'',r' °
'show ''DISPLAY 1 0╟3 3µ∞9'' ''DISPLAY 1╟[1]3 3µ∞9''' °
'''The first expression using Drop contains a zero. This indicates tha °
t''' '''that axis should be left unchanged.''' 'do' °
'''Axis specification in Take and Drop is most useful when used with'' °
' °
'''arrays of rank greater than two. Note that the ordering of axes''' °
'''within the axis specification does not alter the original''' °
'''allocation of axes in the right argument.'',r' 'do' °
'show ''A╜1 2 3µ∞6'' ''DISPLAY 2 1╞[2 1]A'' ''DISPLAY 1 2╞[1 2]A''' °
'''Take and Drop with axis specification leads to the next rule'',r' °
'0 RULE 31' 'do' °
'''Before we leave Take and Drop, let us look at some more examples.'' °
' °
'''To become familiar with these two primitive functions, it is very'' °
' °
'''instructive to try any number of special situations. On the other'' °
' °
'''hand, the mere knowledge of the wide flexibility available with''' °
'''Take and Drop is sufficient. When a practical need arises in the''' °
'''future, you can always refresh your memory by trying out different' °
'' '''cases. So here goes'',r' °
'show ''A╜3 2µ1 2 ''''A'''' 3'' ''DISPLAY A'' ''DISPLAY 3╞[2]A''' °
'''The third column of the last expression reproduces the prototype''' °
'''of the first column.''' 'do' °
'show ''B╜1 2 (3 4)'' ''╧B'' ''╧2╞B''' °
'''The depth of the result need not be the same depth as that of the'' °
' '''right argument.'',r' 'show ''(∞0)╞[∞0]A'' ''(∞0)╟[∞0]A''' °
'''Null vectors in Take and Drop leave the right argument unchanged.'' °
X' 'endd' °
*(1997 6 3 12 44 55 548) °
FTEACH3 ÉFX 'TEACH3' 'Σ Pick and the prototype' 'exit ''TEACH3''' °
''' FIRST'',r' °
'''Earlier we defined the prototype as the fill element for the Take'' °
' °
'''and Drop primitives. Using Drop to generate a null vector, we get'' °
' '''the prototype enclosed in a null box!'',r' °
'show ''DISPLAY ²3╟(1 2) (3 4)''' °
'''Is there a way to retrieve just the prototype? We can try the discl °
ose'',r' 'show ''P╜²3╟(1 2) (3 4)'' ''DISPLAY πP''' °
'''Attempting to disclose the null box, returns a null vector. What''' °
'''we want is to somehow obtain'',r' 'show ''DISPLAY 0 0''' °
'''This is possible to do with the tools available to us so far, but'' °
' '''may be inefficient for large arrays'',r' °
'show ''DISPLAY 3π3╞(1 2) (3 4)''' °
'''There is a special APL2 primitive function that will do this. It is °
''' '''called FIRST, and is none other than monadic Take'',r' °
'show ''DISPLAY ╞P''' °
'''Therefore the idiom that will retrieve the prototype from an array' °
'' '''is "╞0╞"'',r' 'show ''DISPLAY ╞0╞(1 2) ''''ABCD''''''' °
'''To answer your next question, as of now, monadic DROP is undefined. °
''' 'do' °
'''Of course First can also be used to extract the first element from' °
'' '''a vector'',r' °
'show ''DISPLAY 1π(1 2) (3 4)'' ''DISPLAY ╞(1 2) (3 4)''' °
'''So for NON-NULL APL2 vectors, First is equivalent to 1π. What about °
''' '''arrays?'',r' 'show ''DISPLAY ╞2 2µ(1 2) (3 4)''' °
'''This gives us the following rule'',r' '0 RULE 32' °
'''As a corollary, one could say that the prototype of any array is''' °
X '''the same as the prototype of First of that array.''' 'endd' °
*(1997 6 5 13 41 29 444) °
FTEACH4 ÉFX 'TEACH4;WORDS;PUNCTS;PHRASE' 'Σ The EACH opreator' °
'exit ''TEACH4''' °
'''In the previous lesson we used the dyadic enclose function to''' °
'''generate a vector of vectors from a character string'',r' °
'show ''PHRASE╜''''Once upon a time, there was an elf.''''''' °
'show ''WORDS╜(~PHRASEε'''' ,.;:'''')ΓPHRASE''' °
'show ''PUNCTS╜(PHRASEε'''' ,.;:'''')ΓPHRASE'' ''DISPLAY WORDS'' ''DIS °
PLAY PUNCTS''' °
'''The nested vectors WORDS and PUNCTS contain exactly the same inform °
ation''' °
'''as PHRASE. But now the elements of WORDS are in a form that can be' °
'' °
'''manipulated for their semantics, while the elements of PUNCTS provi °
de''' °
'''information about the phrase syntax. Since PHRASE is equivalent to' °
'' °
'''WORDS and PUNCTS, one must ask how could we do the inverse operatio °
n,''' '''namely combine WORDS and PUNCTS to reproduce PHRASE.''' 'do' °
'''To do just that, we now introduce a new APL2 operator. It is called °
''' '''EACH, and is represented by the symbol ■'',r' °
'show ''DISPLAY WORDS,■PUNCTS''' °
'''This is not exactly what we want. We have managed to combine the''' °
'''elements of WORDS and PUNCTS, but we still have a nested vector.''' °
'do' °
'''To convert a nested vector to a simple vector, there is a monadic'' °
' '''function called ENLIST. It is represented by the symbol ε'',r' °
'show ''DISPLAY εWORDS,■PUNCTS''' °
'''The resulting vector is identical to the original PHRASE.''' 'do' °
'''Let us take a closer look at the Each operator.'' r' °
'show ''5+∞5'' ''5+■∞5''' °
'''In the next example, the Each operator also has no effect.'',r' °
'show ''5 10+(1 2) (3 4)'' ''5 10+■(1 2) (3 4)''' °
'''In these examples even though the right argument is nested, the''' °
'''each operator still has no effect. This will be true even when''' °
'''both the left and right argument are nested'',r' °
'show ''(Γ1 2)⌡(1 2) (3 4)'' ''(Γ1 2)⌡■(1 2) (3 4)''' °
'''One may ask, when is the Each operator useful. Here is one example' °
',r' 'show ''DISPLAY ∞■∞4''' °
'''One would be tempted at this point to generalize that expressions'' °
' '''containing only scalar functions are not affected by the Each''' °
'''operator. But this is not quite true, as we can see from the follow °
ing''' '''example'',r' 'show ''+/∞5'' ''+/■∞5''' °
'''In the second expression, the reduction is performed on each''' °
'''element of the vector. Since these elements are simple scalars''' °
'''the result of each reduction is the scalar unchanged''' 'do' °
'''Let''''s see how Each behaves with a non scalar function in reducti °
on'',r' 'show ''DISPLAY ,/∞5'' ''DISPLAY ,/■∞5''' °
'''Can you explain why the first expression returns a scalar?''' 'do' °
'''We can summarize our findings on the each operator'',r' °
'0 RULE 33' 'do' '''Let us try a few more examples'',r' °
'show ''DISPLAY ε■((1 2) (3 4)) (''''ONE'''' ''''TWO'''')''' °
'''In this example we used each on a monadic primitive function''' °
'do' 'show ''+/■2 2µ(1 2) (3 4) (5 6) (7 8)''' °
'''When Each is applied to an array, it will process each element of'' °
X' '''that array.''' 'endd' °
*(1997 6 5 13 42 29 448) °
FTEACH5 ÉFX 'TEACH5;A' 'Σ Enlist and ravel' 'exit ''TEACH5''' °
'''ENLIST and RAVEL'',r' °
'''In lesson 4 we introduced the comma as a primitive function. As a'' °
' °
'''monadic function it is called RAVEL, and as a dyadic function it is °
''' °
'''called CATENATE. In this lesson we also introduced the monadic''' °
'''function called ENLIST. Let us study now how these three primitive' °
'' '''functions work on nested arrays.''' 'do' °
'''First, let us compare enlist to ravel. Ravel converts the contents' °
'' °
'''of any array to a vector. Enlist converts the contents of any array °
''' °
'''to a vector of simple scalars. The difference between these two''' °
'''functions is visible only for APL2 objects of depth 2 or greater'', °
r' 'show ''DISPLAY ,2 2µ∞4'' ''DISPLAY ε2 2µ∞4''' °
'''In these two examples, enlist and ravel produce the same result,''' °
'''because the array is a simple one (all elements are simple scalars) °
'',r' 'show ''DISPLAY ,2 2µ2,/∞5'' ''DISPLAY ε2 2µ2,/∞5''' °
'''In the first expression, ravel keeps the non-simple scalars intact, °
''' °
'''while in the second expression all components of the array are''' °
'''disclosed into a vector of simple scalars.''' 'do' °
'''There are many practical uses of enlist. Consider the following two °
''' '''arrays'',r' 'show ''2 2µ1 2 3 ''''4'''''' ''2 2µ∞4''' °
'''These appear identical, but the first one contains the character 4' °
'' °
'''instead of the scalar integer 4. Function DISPLAY does distinguish' °
'' °
'''between these two arrays, but fails to identify the component that °
is''' '''not an integer'',r' °
'show ''DISPLAY 2 2µ1 2 3 ''''4'''''' ''DISPLAY 2 2µ∞4''' °
'''The + sign on the bottom line of the box of the first array indicat °
es''' °
'''that it is a mixed array containing both characters and numbers.''' °
'do' °
'''We can extract the enlist of the prototype from this array,'',r' °
'show ''DISPLAY ε╞0µΓ2 2µ1 2 3 ''''4''''''' °
'''The resulting vector then can be used not only to tell if the array °
''' °
'''is mixed, but also identify those elements that are characters.''' °
'''The expression ε╞0µΓ is an idiom, but is not the only one that''' °
'''produces this result. You should try to find another expression tha °
t''' '''will have the same effect.''' 'do' °
'''Before we leave ravel, here are some examples of using ravel with'' °
' '''axis specification'',r' °
'show ''DISPLAY ,A╜2 2 2µ∞8'' ''DISPLAY ,[1 2]A'' ''DISPLAY ,[1 2 3]A' °
X'' 'endd' °
*(1997 6 5 13 43 26 440) °
FTEACH6 ÉFX 'TEACH6;A;B;C;D;V;W' 'Σ Catenation' 'exit ''TEACH6''' °
'''CATENATION OF ARRAYS'',r' °
'''We studied catenation as a primitive function that operates on''' °
'''vectors. Catenation can be a very powerful function in the''' °
'''construction of arrays and nested APL2 objects. We will begin with' °
'' '''the catenation of simple arrays'',r' °
'show ''7,2 3µ∞6'' ''(2 3µ∞6),7'' ''(2 3µ∞6),6+∞2'' ''(2 3µ∞6),2 2µ6+∞ °
4''' '''Catenation can be done also with axis specification'',r' °
'show ''7,[1]2 3µ∞6'' ''(2 3µ∞6),[1]6+∞3'' ''(2 3µ∞6),[1]3 3µ6+∞9''' °
'''These results can be summarized with the following rule'',r' °
'0 RULE 34' 'do' °
'''We also displayed an expression catenating a rank 2 array to a''' °
'''vector. The rule for that process is illustrated with the following °
''' '''example'',r' °
'show ''µ(2 3 4µ∞1),2 3µ2'' ''µ(2 3 4µ1),[1]3 4µ2'' ''µ(2 3 4µ1),[2]2 °
4µ2''' '0 RULE 35' 'do' '''Here are some examples of catenation'',r' °
'show ''DISPLAY ,/(1 2 3) (4 5 6)'' ''DISPLAY (1 2 3),■(4 5 6)''' °
'show ''DISPLAY (1 2),(3 4) (5 6)'' ''DISPLAY (1 2),■(3 4) (5 6)''' °
'''As an exercise try to use some of the primitives we have studied''' °
'''so far to generate the following structures starting with the simpl °
e''' '''vectors V╜∞4 and W╜4+∞4'',r' 'V╜∞4' 'W╜4+V' 'A╜V,(πV,■W),W' °
'B╜2,/■V W' 'C╜1,+/■2,/V,W' 'D╜Γ[2]4 2µV,W' °
'show ''DISPLAY A'' ''DISPLAY B'' ''DISPLAY C'' ''DISPLAY D''' 'do' °
''' LAMINATION'',r' °
'''The axis specification need not be an integer. When it is not,''' °
'''the function has another name. It is called LAMINATION. Here is''' °
'''an example of lamination'',r' °
'show ''DISPLAY V,[0.5]W'' ''DISPLAY V,[1.5]W''' °
'''Lamination provides for the extension of rank. The two arguments''' °
'''must have the same shape and rank, or one of them must be a scalar. °
X''' 'endd' °
*(1997 6 5 13 44 32 468) °
FTEACH7 ÉFX 'TEACH7;NOS' 'Σ Reverse, rotate and transpose' °
'exit ''TEACH7''' ''' REVERSE, ROTATE AND TRANSPOSE'',r' °
'''There are two important structural functions that complete the''' °
'''APL2 toolbox. The first one of these is called REVERSE in its''' °
'''monadic form. When used, it reverses the order of elements in''' °
'''an array'',r' 'show ''Φ∞5'' ''Φ3 3µ∞9'' ''Φ[1]3 3µ∞9''' °
'''As any other function, it can be used with the Each operator'',r' °
'show ''Φ(1 2) (3 4) (5 6)'' ''Φ■(1 2) (3 4) (5 6)''' °
'''There is also a form of reverse to operate on the first axis. This' °
'' '''form uses the symbol Θ'',r' °
'show ''NOS╜2 3µ''''ONE'''' ''''TWO'''' ''''THREE'''' ''''FOUR'''' ''' °
'FIVE'''' ''''SIX''''''' 'show ''ΦNOS'' ''ΘNOS''' °
'''When used as a dyadic function, Φ is called rotate. The left argume °
nt''' °
'''is an integer. It specifies the number of elements to be rotated''' °
'''from left to right. A negative value produces a rotation from right °
''' '''to left'',r' 'show ''1Φ∞5'' ''2Φ∞5'' ''²1Φ∞5''' °
'''For arrays of rank 2 or greater, the axis specification can be used °
.''' '''Default is the last axis'',r' °
'show ''1Φ3 3µ∞9'' ''2Φ[1]3 3µ∞9''' °
'''For arrays of rank 2 or greater, the left argument may be a non-sca °
lar.''' °
'''The dimension of the left argument must be equal to ²1╟µR, where R °
is''' °
'''the right argument. This is best illustrated for an array of rank 2 °
'',r' 'show ''0 1 2Φ3 4µ∞12'' ''0 1 2 3Φ[1]3 4µ∞12''' °
'''For arrays of rank greater than 2 we have'',r' °
'show ''(2 3µ∞4)Φ2 3 4µ∞24'' ''(2 4µ∞4)Φ[2]2 3 4µ∞24'' ''(3 4µ∞4)Φ[1]2 °
3 4µ∞24''' °
'''The second structural function is called TRANSPOSE, and it''''s sym °
bol''' °
'''is φ (upper case 6). Transpose has a monadic as well as a dyadic fo °
rm.''' '''Transpose interchanges axes'',r' °
'show ''φ3 3µ∞9'' ''φNOS'' ''µφ2 4µ∞8''' °
'''For arrays of rank greater than 2, the monadic transpose reverses a °
xes'',r' 'show ''µφ2 3 4µ2'' ''µφ1 2 3 4 5µ5''' °
'''The dyadic form of transpose has two versions:'',r' °
''' 1. The left argument specifies the desired ordering of the axe °
s'',r' 'show ''µ2 1 3φ2 3 4µ5'' ''µ3 2 1φ2 3 4µ5''' °
'''In the first example the first axis is placed second, and the secon °
d''' °
'''one is placed first. In the second example the first axis is placed °
''' °
'''third, and the third axis is placed first. (This is the same result °
as''' '''with monadic transpose.)''' 'do' °
'''The second form of the dyadic transpose allows the repetition of ax °
es.''' °
'''This form is a powerful tool in certain applications of math dealin °
g''' '''with tensors. Here are some examples of this second form'',r' °
'show ''3 3µ∞9'' ''1 1φ3 3µ∞9'' ''1 1 2φ3 3 3µ∞27'' ''1 2 1φ3 3 3µ∞27' °
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 15 12 26 13 364) °
Ferase ÉFX 'erase;t;EXIT;GO;HELP;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 6 5 13 40 14 380) °
Frule ÉFX 'V rule W' 'Σ Additional remarks on rules' °
'╕(2=ÉNC ''V'')/L ╪ V╜0' 'L:╕(~(╞W)ε∞8)/LA ╪ V rulea╞W ╪ ╕L0' °
'LA:╕(~(╞W)ε9 10 11)/LB ╪ V ruleb╞W ╪ ╕L0' °
'LB:╕(~(╞W)ε11+∞8)/LC ╪ V rulec╞W ╪ ╕L0' °
'LC:╕(~(╞W)ε19+∞10)/LD ╪ V ruled╞W ╪ ╕L0' °
'LD:╕(30 31 32 33 34 35=╞W)/L30,L31,L32,L33,L34,L35' °
'''This rule number is undefined'' ╪ ╕' '╕(0=V)/L0' 'L30:╕(V>1)/L30X' °
''' RULE 30. The length of left argument to both TAKE and DROP must °
''' °
''' equal the rank of the right argument. The exception: a' °
'' °
''' scalar left argument can be applied to a right argument °
''' ''' vector.'',2µr' '╕(0=V)/L0' °
'L30X:''A zero is permissible on both take and drop. A null vector is °
not.''' '╕L0' 'L31:╕(V>1)/L31X' °
''' RULE 31. For TAKE and DROP with axis specification, every''' °
''' integer in the left argument must be matched with''' °
''' a valid axis in brackets. Axes may not be duplicated.'' °
' °
''' The length of the left argument may be less than the''' °
''' rank of the right argument with axis specification.'',2 °
µr' '╕(0=V)/L0' 'L31X:''Any axes not specified are left unchanged.''' °
'╕L0' 'L32:╕(V>1)/L32X' °
''' RULE 32. Monadic Take extracts the contents of the first scalar' °
'' °
''' (rank 0 array) in an array, regardless of its rank.''' °
''' It is called FIRST.'',2µr' '╕(0=V)/L0' °
'L32X:''The FIRST of an empty array returns the prototype.''' '╕L0' °
'L33:╕(V>1)/L33X' °
''' RULE 33. The each operator can be placed to the right of a''' °
''' function, or to the right of an operator. When used,''' °
''' it applies the combined function separately to every''' °
''' element of the argument.'',2µr' '╕(0=V)/L0' °
'L33X:''This operator is so powerful that it is tempting to over-use i °
t.''' °
'''As you excercise your APL2 skills, try to solve problems without''' °
'''the EACH operator as much as possible.''' '╕L0' 'L34:╕(V>1)/L34X' °
''' RULE 34. A rank 0 array, or another array can be catenated to an °
''' °
''' array. When two arrays are catenated, the matching dime °
nsion''' ''' of the two arrays must be the same.'',2µr' °
'╕(0=V)/L0' °
'L34X:''Catenation does not increase depth. The result will have the d °
epth''' '''of the component of greatest depth.'',r' °
'show ''╧3 3µ∞9'' ''╧Γ∞5'' ''╧(3 3µ∞9),Γ∞5''' '╕L0' 'L35:╕(V>1)/L35X' °
''' RULE 35. Two arrays can be catenated if their rank differs by 1. °
''' °
''' The shapes of dimensions not catenated MUST MATCH!'',2µ °
r' '╕(0=V)/L0' °
'L35X:''Naturally, to catenate along other than the last dimension, an °
axis''' '''specification can also be used here.''' 'L0:do' °
X '╕(0=µW╜1╟W)/0' '╕L' °
*(1997 6 1 12 42 53 524) °
Frulea ÉFX 'V rulea W' 'Σ Additional remarks on rules' °
'╕(2=ÉNC ''V'')/L ╪ V╜0' 'L:╕(W=∞8)/L1,L2,L3,L4,L5,L6,L7,L8' °
'''For rules not described in this lesson, see workspace INDEX''' °
'╕0' 'L1:╕(V>1)/L1X' °
'''RULE 1. For arithmetic operations a vector must be matched with a'' °
' ''' scalar, or another vector of the same length.'',2µr' °
'╕(0=V)/0' °
'L1X:''This is the first of many rules dealing with the concept of''' °
'''CONFORMABILITY. This means that elements to be processed by APL2''' °
'''must in some ways match.''' '╕0' 'L2:╕(V>1)/L1X' °
'''RULE 2. The reduction operator places the function, (specified to'' °
' °
''' its left), between all pairs of the vector. It then evaluat °
es''' ''' the resulting expression.'',2µr' '╕(0=V)/0' °
'L2X:''There is more to this, but at this stage the rule is essentiall °
y''' '''correct.''' '╕0' 'L3:╕(V>1)/L1X' °
'''RULE 3. All APL2 expressions are evaluated from right to left'',2µr °
' '╕(0=V)/0' °
'L3X:''This rule is valid in APL, which is the earlier version of APL2 °
.''' °
'''For APL2, the rule has been restated in a totally different way.''' °
'''However until we introduce some concepts that are new to APL2, the' °
'' '''newer form reduces to RULE 3 as stated.''' '╕0' 'L4:╕(V>1)/L1X' °
'''RULE 4. Vectors in APL2 can have lengths of zero and one.'',2µr' °
'╕(0=V)/0' °
'L4X:''This is the first concept that begins to introduce the idea tha °
t no''' °
'''matter what the APL expression, if it is valid, it must produce a'' °
' °
'''valid APL2 object. (Shades of which came first, the chicken or the °
egg)''' '╕0' 'L5:╕(V>1)/L1X' °
'''RULE 5. The shape of a variable is a vector. The shape of a vector' °
'' ''' is a vector of length 1. The shape of a scalar is a''' °
''' vector of length zero.'',2µr' '╕(0=V)/0' °
'L5X:''The left argument of RESHAPE is by definition a vector. If APL2 °
is''' °
'''to be internally consistent, the inverse operation to RESHAPE (whic °
h''' '''is indeed SHAPE) MUST return the same type of object.''' '╕0' °
'L6:╕(V>1)/L1X' °
'''RULE 6. Reduction of a scalar returns that scalar REGARDLESS of''' °
''' the function to the left of the reduction operator.'',2µr' °
'╕(0=V)/0' °
'L6X:''Reduction BY DEFINITION reduces the RANK by one. The exception °
is''' °
'''for objects whose rank is zero. Since there is no such thing as''' °
'''negative rank, reduction is undefined for scalars, and therefore''' °
'''the result is to leave the APL2 object unchanged.''' '╕0' °
'L7:╕(V>1)/L1X' °
'''RULE 7. The reduction of a null vector produces the identity''' °
''' element of the function.'',2µr' '╕(0=V)/0' °
'L7X:''A null vector may be empty, but it still has rank equal to one. °
''' °
'''Therefore its reduction MUST be a scalar. Since there is no data''' °
'''in a null vector, the scalar must be such that it has no effect''' °
'''on the operation performed by the function: Zero added to anything' °
'' °
'''has no effect in addition; one multiplied by anything has no effect °
''' '''in multiplication; and so on.''' '╕0' 'L8:╕(V>1)/L1X' °
'''RULE 8. Parentheses can (and should) be used to modify the right''' °
''' to left rule to improve efficiency'',2µr' '╕(0=V)/0' °
'L8X:''Parentheses are used in APL2 for other purposes as well, but fo °
r''' °
'''now, we will use them just to modify the right to left rule (RULE 3 °
).''' °
'''If you place parentheses where they are not needed, APL2 will ignor °
Xe''' '''them.''' °
*(1997 6 1 12 49 37 488) °
Fruleb ÉFX 'V ruleb W' 'Σ Additional remarks on rules' °
'╕(2=ÉNC ''V'')/L ╪ V╜0' 'L:╕(9 10 11=╞W)/L9,L10,L11 ╪ ╕0' °
'L9:╕(V>1)/L9X' °
''' RULE 9: To produce a quote inside a character string, enter''' °
''' the quote twice.'',2µr' '╕(0=V)/0' °
'L9X:''This is used in most other programming languages.''' '╕0' °
'L10:╕(V>1)/L10X' °
''' RULE 10: In replication the left argument must contain only''' °
''' integers. The length of the left argument must be''' °
''' the same as the length of the right argument.'',2µr' °
'╕(0=V)/0' °
'L10X:''The left argument may also have negative integers. Only the nu °
mber''' °
'''of positive integers and zeros must add up to the length of the rig °
ht''' °
'''argument. Replicate with negative integers is not discussed here be °
cause''' °
'''the explanation requires concepts that have not yet been mentioned. °
'',r' 'show ''1 1 2 ²1 0 1 1 1 ²1 1 0 1 1/''''CALIFORNIAN''''''' '╕0' °
'L11:╕(V>1)/L11X' °
''' RULE 11: The expression inside square brackets must return''' °
''' positive integers in the range of the length of''' °
''' the indexed vector. If the expression is MISSING,''' °
''' the result is as if the brackets were missing.'',2µr' °
'╕(0=V)/0' °
'L11X:''The expression in brackets need not be a vector. It could be a °
n''' '''array as in the next example'',r' °
X 'show ''''''CALIFORNIA''''[3 3µ?9µ10]'' ''(∞4)[3 3µ∞4]''' °
*(1997 6 2 12 11 17 260) °
Frulec ÉFX 'V rulec W' 'Σ Additional remarks on rules' °
'╕(2=ÉNC ''V'')/L ╪ V╜0' °
'L:╕((11+∞8)=╞W)/L12,L13,L14,L15,L16,L17,L18,L19' 'L12:╕(V>1)/L12X' °
''' RULE 12. A scalar function is one that will produce a result on' °
'' °
''' every scalar element of a vector or array. EXAMPLES:''' °
''' + - ⌡ ÷ * are numeric scalar functions. , µ ∞ are NOT'' °
' ''' scalar functions.'',r' '╕(0=V)/0' °
'L12X:''This distinction will become clearer when we study more genera °
lized''' '''arrays.''' '╕0' 'L13:╕(V>1)/L13X' °
''' RULE 13. Scalars that work with vectors also work with arrays.'' °
,r' '╕(0=V)/0' °
'L13X:''No problem with simple scalars, but this rule may need modific °
ation''' °
'''when we deal with "rank zero arrays" that are not simple scalars.'' °
' '╕0' 'L14:╕(V>1)/L14X' °
''' RULE 14. Arrays with the same shape can be processed with scalar °
''' '''functions.'',r' '╕(0=V)/0' °
'L14X:''Arrays with distinct shapes can be processed as we shall see, °
but''' °
'''there will be restrictions, and we will use new operators.''' '╕0' °
'L15:╕(V>1)/L15X' °
''' RULE 15. The number of semicolons inside brackets must equal the °
''' ''' rank of the array MINUS 1.'',r' '╕(0=V)/0' °
'L15X:''There is no further generalization to this rule.''' '╕0' °
'L16:╕(V>1)/L16X' °
''' RULE 16. An axis specification can be a scalar, a vector or a''' °
''' null vector.'',r' '╕(0=V)/0' °
'L16X:''Recall that null array is the ONLY bracket specification that' °
'' °
'''makes sense for a scalar. We will use that property when dealing wi °
th''' '''rank 0 arrays.''' '╕0' 'L17:╕(V>1)/L17X' °
''' RULE 17. An axis specification can be any array containing''' °
''' valid integers.'',r' '╕(0=V)/0' °
'L17X:''With this rule, you can generate an APL2 object of arbitrary'' °
' '''rank.''' '╕0' 'L18:╕(V>1)/L18X' °
''' RULE 18. The shape of the result of axis specification is the''' °
''' catenation of the shapes of expressions inside brackets °
.''' °
''' If the expression for an axis is missing, the shape for °
''' ''' that axis is unchanged.'',r' '╕(0=V)/0' °
'L18X:''This is merely the rule for implementation of rule 17.''' °
'╕0' 'L19:╕(V>1)/L19X' °
''' RULE 19. Simple reduction of arrays removes its last dimension.' °
X',r' '╕(0=V)/0' 'L19X:''This is a generalization of rule 2.''' '╕0' °
*(1997 6 3 12 4 29 284) °
Fruled ÉFX 'V ruled W' 'Σ Additional remarks on rules' °
'╕(2=ÉNC ''V'')/L ╪ V╜0' °
'L:╕(W=19+∞10)/L20,L21,L22,L23,L24,L25,L26,L27,L28,L29' °
'''This rule number is undefined'' ╪ ╕' 'L20:╕(V>1)/L20X' °
''' RULE 20. The depth of an APL array is defined as the maximum''' °
''' depth to reach a simple scalar.'',2µr' '╕(0=V)/0' °
'L20X:''The concept of depth provides the means of building complex da °
ta''' °
'''structures. This is the first of several rules dealing with depth.' °
'' '╕0' 'L21:╕(V>1)/L21X' °
''' RULE 21. No APL2 expression can generate a depth 1 object contai °
ning''' °
''' ONLY a scalar. (Or, a scalar can not have depth 1.)'',2 °
µr' '╕(0=V)/0' °
'L21X:''This rule can be treated as an axiom of APL2. In theory it is' °
'' °
'''possible to enclose a scalar, but that would lead to a significantl °
y''' °
'''different language. EXAMPLE: The reduction of a vector must return' °
'' °
'''a scalar. Doing repeated reduction could produce enclosed scalars'' °
' °
'''that would require removal of such depths before allowing compariso °
ns.''' '╕0' 'L22:╕(V>1)/L22X' °
''' RULE 22. The depth of an array is given by the maximum length of °
''' °
''' the access vector associated with that array.'',2µr' °
'╕(0=V)/0' °
'L22X:''When you use function DISPLAY, depth can be obtained by counti °
ng''' °
'''the number of boxes you must cross from outside to reach the innerm °
ost''' '''scalar.''' '╕0' 'L23:╕(V>1)/L23X' °
''' RULE 23. Null elements of an access vector must be included to'' °
' ''' match corresponding rank zero arrays.'',2µr' °
'╕(0=V)/0' °
'L23X:''The access vector works from left to right. The leftmost eleme °
nt''' °
'''removes the outermost box, and the rightmost element removes the''' °
'''innermost box.''' '╕0' 'L24:╕(V>1)/L24X' °
''' RULE 24. The monadic disclose of a rank 0 array reveals the cont °
ents''' ''' of that array.'',2µr' '╕(0=V)/0' °
'L24X:''This is a consequence of rule 21. A simple scalar is immune to °
''' '''to the process of enclosure or disclosure.''' '╕0' °
'L25:╕(V>1)/L25X' °
''' RULE 25. The monadic disclose (without axis specification) reduc °
es''' °
''' depth by one, by adding a new last axis to the disclose °
d''' °
''' elements. FILL elements are used to complete the array. °
'',2µr' '╕(0=V)/0' °
'L25X:''The fill element for numberic arrays is zero. The fill element °
for''' °
'''character arrays is a blank. The fill element for mixed arrays in'' °
' '''APL2 will be discussed in later sessions.''' '╕0' °
'L26:╕(V>1)/L26X' °
''' RULE 26. Simple disclose requires that all components of a neste °
d''' °
''' array have the same rank (or be rank 0 arrays).'',2µr' °
'╕(0=V)/0' °
'L26X:''We use the phrase ''''simple disclose'''' because, as we will °
learn''' °
'''later, you can define your own rules on how to disclose nested''' °
'''arrays.''' '╕0' 'L27:╕(V>1)/L27X' °
''' RULE 27. Forms can be equivalent only if all rank 0 arrays conta °
in''' °
''' the same rank and shape (or rank 0 arrays)--recursively °
--'',2µr' '╕(0=V)/0' °
'L27X:''Earlier we discussed functions that are dual. These are one to °
''' °
'''one transformations of data. Equivalent forms can be thought of as' °
'' '''a kind of dual representation of data structures.''' '╕0' °
'L28:╕(V>1)/L28X' °
''' RULE 28. A zero in a partition vector will remove the associated °
''' ''' element.'',2µr' '╕(0=V)/0' °
'L28X:''The components of a partition vector must be positive integers °
or''' °
'''zero. The presence of a zero is treated much the same as in boolean °
''' '''reduction.''' '╕0' 'L29:╕(V>1)/L29X' °
''' RULE 29. Each place in the partition vector, where the value''' °
''' INCREASES marks a partition.'',2µr' '╕(0=V)/0' °
'L29X:''A partition must ocurr BETWEEN two consecutive elements. These °
''' '''need not be simple scalars'',r' °
X 'show ''DISPLAY (1 1 2 2)Γ(1 2) ''''AB'''' (3 4) ''''C''''''' '╕0' °
*(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 3 43 352) °
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' °