home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH9A.ATF
< prev
next >
Wrap
Text File
|
1997-09-18
|
56KB
|
686 lines
XNÉIO 0 1 °
XNÉCT 0 1E²13 °
XCÉFC 1 6 .,*0_² °
XNÉRL 0 784558821 °
XCÉPR 1 1 °
XCÉLX 1 5 TEACH °
XCA 2 2 26 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ °
XNARRAY 3 4 1 2 2 1 4 2 4 4 5 2 °
*(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' °
XAD╜('ONE')('TWO')((1µ1)(1 2)(1 2 3))(2) °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1996 4 6 16 4 15 244) °
FDISPLAY ÉFX 'D╜S DISPLAY A;ÉIO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B' °
'Σ DISPLAY A GENERAL ARRAY IN PICTORIAL FORM' °
'Σ NORMAL CALL IS MONADIC. DYADIC CALL USED ONLY IN' °
'Σ RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.' 'ÉIO╜0' °
'»(0=ÉNC ''S'')/''S╜µA''' 'R╜╞µ,S Σ PSEUDO RANK.' °
'C╜''┐┌└┘'' Σ UR, UL, LL, AND LR CORNERS.' °
'HL╜''─'' Σ HORIZONTAL LINE.' °
'HC╜HL,''Θ╕'',HL,''~+ε'' Σ HORIZONTAL BORDERS.' °
'HT╜HC[(0<R)⌡1+0<╞²1╞,S]' 'ΣW╜,0╧■╞0µΓ(1⌐µA)╞A' °
'HB╜HC[3+3╛(''2⌡~A╧«A'' ÉEA ''1+╞ε0⌡(1⌐⌡/µA)╞,A'')+3⌡1<µµS]' °
'VL╜''│'' Σ VERTICAL LINE.' °
'VB╜VL,''Φ╟'' Σ VERTICAL BORDER.' °
'V╜VB[(1<R)⌡1+0<²1╞²1╟,S]' °
'»(0εµA)/''A╜(1⌐µA)µΓ╞A'' Σ SHOW PROTOTYPE OF EMPTIES.' °
'╕(1<╧A)/GEN' '╕(2<µµA)/D3' °
'D╜«A Σ SIMPLE ARRAYS.' 'W╜1╞µD╜(²2╞1 1,µD)µD' °
'N╜²1+1╟µD' '╕(0=µµA)/SS' °
'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[ °
3]' '╕0' 'SS:HB╜((0 '' '')=╞0µΓA)/'' -''' °
'D╜'' '',('' '',[0]D,[0]HB,Nµ'' ''),'' ''' '╕0' °
'GEN:D╜«DISPLAY■A Σ ENCLOSED ...' 'N╜Dδ.⌠'' ''' °
'D╜(Nδ~1ΦN)≡D' 'D╜(δ≡~'' ''╤D)/D' 'D╜((1,µS)µS)DISPLAY D' °
'╕(2≥µ,S)╟D3E,0' 'D3:D╜0 ²1╟0 1╟«ΓA Σ MULT-DIMENSIONAL ...' °
'W╜1╞µD' 'N╜²1+1╟µD' °
'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[ °
3]' 'D3E:N╜²2+µ,S' °
X 'V╜C[Nµ1],[0]VB[1+0<²2╟,S],[0](((²3+╞µD),N)µVL),[0]C[Nµ2]' 'D╜V,D' °
*(1996 4 6 16 4 15 244) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1996 4 6 16 4 15 244) °
FGO ÉFX 'GO;T;E;B' 'Σ Expression driver' 'L0:B╜E╜''''' 'æ╜'' ''' °
'T╜æ' '╕(^/'' ''=T)/L0' '╕((^/'')OFF ''=5╞6╟T)doif ''EXIT'')/0' °
'╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/L0' °
'''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/L0' '╕B/L0' °
'''This is not a valid APL2 expression''' 'æ╜''*''' °
X '╕(''?''⌠╞1╟æ)/L0' 'E' '╕L0' °
*(1997 8 15 12 55 31 552) °
FHELP ÉFX 'HELP;N;I;T' 'Σ Help to student' '''WHAT TO DO'',r' °
''' ° To get out of the lesson''' ''' ENTER: EXIT''' °
''' ° To log off APL2''' °
''' FIRST, ENTER: EXIT THEN ENTER: )OFF''' °
''' ° To get help''' ''' ENTER: HELP''' °
''' ° When you see the prompt on a blank line''' °
''' ENTER AN APL2 EXPRESSION - OR JUST PRESS: ENTER''' 'do' °
''' ° If you get this line'',r' °
'''This is not a valid APL2 expression'',r,''*'',r' °
''' YOU CAN EITHER''' ''' A. PRESS: ENTER''' °
''' B. PRESS: ? and then ENTER to see what was incorrect''' °
''' in your expression causing that response'',r' 'do' °
'''HINTS'',r' °
'''This lesson is made up of '',(«N╜6),'' components named TEACHx, whe °
re''' '''the x stands for a digit:'',r' 'I╜0' °
'L0:T╜''TEACH'',(«I╜I+1)' 'T,'' '',1╟notb(ÉCR T)[2;]' '╕(N>I)/L0' °
'do' °
'''You may review either of these components separately. To do that,'' °
' °
'''first enter EXIT (and RETURN), then enter the name of the lesson.'' °
' '''component (e.g. TEACH4).'',r' °
'''To re-start the lesson, just enter TEACH'',r' °
'''When the screen fills up, it is a good idea to move the cursor to'' °
' '''the start of a convenient paragraph, and press ENTER'',r' °
'''You may also wish to press PAGE UP to review the prevous pages.''' °
'do' '''RESOURCES'',r' °
'''You may also enter ONE of the following words at a time'',r' °
X '''BIND To display the APL2 binding rules''' '''''' 'endd' °
XCSEQUENCE 1 20 aAbBcCdDeEfFgGhHiIjJ °
*(1997 7 4 12 0 33 292) °
FTEACH ÉFX 'TEACH' 'Σ Start lesson 9; APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' 'TEACH1 Σ Binding rules' °
'TEACH2 Σ Examples using binding rules' °
'TEACH3 Σ Grade up and grade down' °
'TEACH4 Σ Atomic vector; its usage in grade functions' °
'TEACH5 Σ Terminal control; atomic function' °
X 'TEACH6 Σ System commands' 'problems' °
*(1997 6 13 12 53 17 472) °
FTEACH1 ÉFX 'TEACH1' 'Σ Theory of APL2, Binding rules' °
'exit ''TEACH1''' °
'''The previous 8 lessons have covered many, but not all of the''' °
'''elements of APL2. It is appropriate at this point to review some''' °
'''of the theoretical foundations of the language.''' 'do' °
'''The original APL was designed as a compact notation to be used''' °
'''by people to describe algorithms. The initial emphasis was mainly'' °
' °
'''that of a mathematical-like notation. The objects that the language °
''' °
'''supported were to a large extent the types of constructs that are'' °
' '''used in mathematics.'',r' °
'''As the language evolved, the scope of applications expanded to''' °
'''eventually cover many fields in Computer Science. This growth''' °
'''resulted in ever increasing pressures to add new features to the''' °
'''language. Fortunately, those who controlled these developments mana °
ged''' °
'''to resist the temptation to add on haphazardly. Instead growth was' °
'' °
'''contained in a strict theoretical boundary. Any changes had to stay °
''' °
'''within a consistent logical framework. To the extent that the initi °
al''' °
'''architecture proved inadequate, new, more general but still rigorou °
s''' °
'''foundations were laid. With very few exceptions, these changes kept °
''' '''earlier versions ''''upward compatible''''.''' 'do' °
'''APL2 is the most recent and also the most powerful implementation'' °
' °
'''of the language. As we describe its structure, syntax and semantics °
,''' °
'''we will also contrast the current features with some of the early'' °
' '''approaches.''' 'do' °
'''APL2 is a computer language that supports three types of objects:'' °
,r' ''' 1 DATA'',r,'' 2 FUNCTIONS'',r,'' 3 OPERATORS'',r' °
'''In addition, there are special symbols for control of syntax.''' °
'do' °
'''Data can be entered from the keyboard, can be generated by function °
s''' °
'''or can be read from files. There are two types of primitive data ty °
pes:''' °
'''NUMBERS and CHARACTERS. APL does not make distinctions between "int °
egers",''' °
'''"reals" and "complex" numbers. The APL2 processor recognizes these °
numeric''' '''types and deals with them apropriately.'',r' °
'''Data can be stored in VARIABLES. The general name for data is ARRAY °
.''' °
'''The contents of data is a collection of items. DATA have three''' °
'''important properties:'',r,r,'' SHAPE'',r,'' RANK'',r,'' TYPE'',r' °
'''SHAPE describes the organization of data as a rectangular object.'' °
' °
'''RANK gives the number of dimensions of the orthogonal collection.'' °
' °
'''TYPE describes the contents of the array. Type includes numeric,''' °
'''character or mixed. Finally the elements of an array can be arrays. °
''' °
'''When the elements of an array are not SIMPLE SCALARS, the arays are °
''' '''said to be NESTED.'',r' °
'''Special names are given to arrays of rank zero and one. Arrays of r °
ank''' °
'''zero are called RANK 0 ARRAYS, but for brevity they may be also cal °
led''' '''SCALARS. Arrays of rank ONE are called VECTORS.''' 'do' °
'''There are two types of functions: primitive and user defined. Funct °
ions''' °
'''generally operate on data to produce transformed data. (Graphics an °
d''' °
'''communications with "external" files will be discussed in lessons'' °
' °
'''dealing with "shared variables" and "associated processors".)'',r' °
'''An APL2 expression is a sequence of APL2 characters that satisfies °
the''' °
'''syntax and semantics of the APL2 language. As part of this syntax, °
APL2''' °
'''also supports objects called OPERATORS. An Operator is a symbol or °
label''' °
'''that modifies the manner in which a function (or another operator)' °
'' °
'''is to be evaluated. Finally, there are special symbols that are use °
d''' °
'''to provide the needed flexibility in writing APL2 expressions.''' °
'do' °
'''The early versions of APL followed a simple left to right rule for °
the''' °
'''execution of an expression. Although this rule is still valid, it i °
s''' °
'''only as a general principle. In detail, the sequence of evaluation °
is''' °
'''controlled by a set of rules dealing with the concept of BINDING.'' °
,r' °
'''In the following listing of these binding rules, those on top take' °
'' °
'''take precedence over those below. (Note that for rule 3, marked wit °
h an''' '''*, we have yet to study an example.)'',r' °
''' 1. Square brackets are bound to the left''' °
''' 2. Binding of assignment arrow to its left expression''' °
'''*3. An operator is bound to its right operand''' °
''' 4. Vector binding (includes strand notation of variables)''' °
''' 5. Binding of operator to its left operand''' °
''' 6. Binding of function to its left argument''' °
''' 7. Binding of function to its right argument''' °
''' 8. Binding of assignment symbol to its right''' 'do' °
'''Binding rule 1 differs in APL2 from APL. In APL the expression'',r' °
''' 2 3 4[2]'',r' °
'''returned 3. In APL2 this expression is no longer valid, because''' °
'''by rule 1 the [2] binds strictly to 4. Since a scalar integer canno °
t''' °
'''be indexed, the expression will in APL2 generate an error message.' °
'' 'do' °
'''In previous lessons we used provisional rules as an aid in helping °
you''' °
'''remember how APL2 behaves given specific expressions. In this and i °
n''' °
'''subsequent lessons, these rules will no longer be available. In the °
ir''' °
'''place, you can enter BIND to get a listing of the binding rules. Al °
so,''' °
'''if you no longer remember how a specific function (symbol) works, y °
ou''' °
'''should try it out. Trial and error is an excellent teacher.''' °
X 'endd' °
*(1997 6 9 12 41 32 468) °
FTEACH2 ÉFX 'TEACH2;A;B;C' °
'Σ Application of binding rules to specific expressions; references' °
'exit ''TEACH2''' °
'''Here are some other examples of the application of binding rules'', °
r' 'show ''(2 3 4)[2]''' °
'''The use of parentheses modifies the scope of rule 1.'',r' 'do' °
'show ''+/3 4 5''' °
'''By rule 4 the vector 3 4 5 is treated as a single entity. Then by'' °
' °
'''rule 5, the operator / is bound to the left function (+). The resul °
ting''' '''compound function +/ is then applied to the vector.''' 'do' °
'show ''2,5++/3 4 5''' °
'''By rule 6 the left + is bound to the 5 only, and by rule 7 the''' °
'''subexpression 5+ is applied to the result of +/3 4 5.''' 'do' °
'(A B)╜''ONE'' ''TWO''' 'show ''A'' ''B'' ''DISPLAY A B C╜∞■∞3''' °
'''The Each operator has only a left operand (rule 3 does not apply he °
re).''' °
'''The Each operator binds to the left, so that the compound function °
∞■ is''' °
'''applied to the result of ∞3. The assignment arrow binds by rule 2 t °
o the''' °
'''expression to the right. Strand notation of variables has a binding °
''' °
'''below 2, so the assignment of the expression to the left goes to C. °
''' 'do' 'show ''DISPLAY 3╞A D╜A B C,2''' °
'''By rule 2 the assignment arrow is bound to the label D. Then by rul °
e''' °
'''4 (from right to left) the strands A B C and A D are bound together °
.''' °
'''The array A B C is then bound to , and 3 is bound to ╞ by rule 6. T °
hen''' °
'''by rule 7, the scalar 2 is catenated to array A B C, and A D is bou °
nd''' '''to 3╞. Finally by rule 8, A B C,2 is bound to D''' 'do' °
'show ''(A B C)╜∞■∞3'' ''DISPLAY A B C''' °
'''The parentheses are used to combine A B and C in strand notation.'' °
' °
'''The assignment of the three element (nested) vector ∞■∞3 is therefo °
re''' '''distributed among these three objects.''' 'do' °
'show ''2+/[1]3 3µ∞9''' °
'''By rule 1, [1] is bound to the reduction operator. By rule 4, the'' °
' °
'''vector 3 3 is bound next. Then by rule 5 the + is bound to /[1].''' °
'''The compound function +/[1] is applied to the left argument 2, and' °
'' '''to the right argument 3 3µ∞9.''' 'do' °
'show ''∞µ''''ONE'''' 2 3''' °
'''By rule 4 the elements ''''ONE'''' 2 3 are bound together as a vect °
or.''' °
'''the monadic function µ is then applied to this vector, producing''' °
'''a vector of length 1. The monadic function ∞ can be applied only to °
''' °
'''a positive scalar integer (or zero). APL2 allows one exception to'' °
' °
'''this rule, namely a one element vector containing a positive intege °
r''' '''(or zero).''' 'do' °
'''The following expression is not valid!'',r' °
'show ''∞■µ■''''ONE'''' 2 3''' °
'''The vector obtained from µ■''''ONE'''' 2 3 includes two null vector °
s, since''' °
'''the shape of a simple scalar is a null vector. The monadic ∞ does n °
ot''' '''accept a null vector as a right argument.''' 'do' °
'''For a more detailed discussion of the principles of APL2, you can'' °
' '''order the following FREE publication from IBM:'',r' °
'''The Principles of APL2, by Dr. James A. Brown TECHNICAL REPORT''' °
'''03.247 (March 1984).'',r' °
'''For a copy, write to:'','' APL Products'',r,''IBM Santa Teresa, M4 °
6/D12''' '''P. O. Box 49023'',r,''San Jose, CA 95161-9023''' 'do' °
'''For the theory of Nested Arrays, empty Arrays, and Prototypes, see: °
'',r' °
'''The Nested Rectangular Array as a Model of Data, by Trenchard Moore °
''' °
'''APL79 Conference Proceedings (APL QUOTE QUAD v. 9 No. 4 June 1979'' °
X' '''pp. 55-73).''' 'endd' °
*(1997 8 29 13 22 37 504) °
FTEACH3 ÉFX 'TEACH3;A;B;C;D' °
'Σ New primitives; Grade up and Grade down' °
'''We now proceed to study additional APL2 primitive functions.''' °
'exit ''TEACH3''' 'do' °
'''Many of the APL2 primitives studied so far are supported by other'' °
' °
'''programming languages. It is a valid question to ask, what criteria °
''' °
'''does one seek in deciding what should become part of the language,' °
'' °
'''and what should be left to be defined by the user of that language. °
'',r' °
'''The APL2 policy has to my knowledge not been explicitly stated, but °
''' °
'''from the availability of existing primitive functions, these must'' °
' '''satisfy at least the following two criteria:'',r' °
''' 1. A function must be either well known and in common use by the' °
'' °
''' computer user community, or be clearly powerful enough to''' °
''' attract potential users, when it becomes available.''' °
''' 2. A primitive function should solve a class of problems in a''' °
''' general but optimal way. The algorithm may be such that many'' °
' °
''' potential users would normally find it inconvenient, if not''' °
''' difficult to develop on their own.''' 'do' °
'''The primitive function described next is a good example of such''' °
'''a function. It is called GRADE, and it has two versions. There is'' °
' °
'''GRADE UP (√), and GRADE DOWN (ⁿ). Both versions when applied to''' °
'''arrays will produce an integer vector. This vector, when inserted'' °
' °
'''in bracket indexing, will produce the array in sorted sequence.''' °
'''For grade up, the sequence will be increasing, and for grade down'' °
' '''the sequence will be decreasing.''' 'do' °
'''The grade function is TYPE sensitive. The monadic version works''' °
'''only on numeric arrays, and the dyadic version works only on''' °
'''character arrays. Mixed arrays cannot be sorted with either version °
''' '''of this primitive function.'',r' °
'''Let us first study the monadic version of grade'',r' °
'show ''VECTOR╜?10µ50'' ''VECTOR'' ''B╜√VECTOR'' ''B'' ''VECTOR[B]''' °
'''The grade up function generates a vector of integers from 1 to µVEC °
TOR.''' °
'''The numeric values of these integers point to the elements in the'' °
' °
'''original vector that will produce the sequence in an increasing ord °
er.''' 'do' 'show ''B[√B]''' °
'''The grade vector when sorted, reproduces the original sort. Note th °
at''' '''this is NOT the same as'',r' 'show ''VECTOR[√√VECTOR]''' °
'show ''VECTOR[ⁿVECTOR]'' ''VECTOR[ΦB]''' °
'''Grade down is equivalent to reversing the grade up vector.''' °
'''To study how sort works when the vector contains repeated values,'' °
' '''consider the following expressions'',r' °
'show ''VECTOR╜2/VECTOR'' ''VECTOR'' ''SEQUENCE╜''''aAbBcCdDeEfFgGhHiI °
jJ''''''' 'show ''SEQUENCE[√VECTOR]''' °
'''We have replicated VECTOR, and then applied the sort function to''' °
'''the alphabetic string SEQUENCE. The paired duplicate values occur'' °
' '''in their original sequence.''' 'do' °
'''The grade function will work on the first dimension of an array of °
rank''' '''two or greater'',r' °
'show ''ARRAY╜?7 3µ50'' ''ARRAY[3 5 7;1]╜ARRAY[1;1]''' °
'''We have set the odd row numbers of column 1 to the same number, so' °
'' '''that we can see how the sort will work'',r' °
'show ''ARRAY'' ''ARRAY[√ARRAY;]''' °
'''Notice that for the same row numbers in the first column, it is the °
''' °
'''second column that is sorted. (If both the first and second column' °
'' °
'''have the same values, then sort uses the third column and so on.)'' °
' 'do' °
'''The grade function does not allow an axis specification. Suppose th °
at''' '''we desire to sort φARRAY by columns'',r' °
'show ''φARRAY'' ''(φARRAY)[;√ARRAY]'' ''φARRAY[√ARRAY;]''' °
'''The grade function also works for arrays of rank greater than 2'',r °
X' 'show ''ARRAY╜?4 1 2µ5'' ''ARRAY'' ''ARRAY[√ARRAY;;]''' 'endd' °
*(1997 6 9 13 21 50 464) °
FTEACH4 ÉFX 'TEACH4;ALPHA;TEXT;STRING;NOS' 'Σ Dyadic GRADE' °
'exit ''TEACH4''' °
'''For character arrays it is not clear a-priori how one should''' °
'''arrange the sort sequence of characters. Clearly for letters we''' °
'''have the alphabetic sequence, but then, where should we place''' °
'''character digits and special symbols? Because of the possibly''' °
'''arbitrary way of deciding what the sort sequence should be, APL2''' °
'''requires a left argument to Grade of text arrays.'',r' °
'show ''ALPHA╜''''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''''' ''TEXT╜''''ONE TWO' °
'''''' 'show ''TEXT[ALPHA√TEXT]''' °
'''Actually, there is a default sort sequence for all characters. It'' °
' '''is based on the COLLATING SEQUENCE of the 256 standard EBCDIC''' °
'''characters. In the IBM 370 architecture, a character is defined as' °
'' °
'''a sequence of 8 bits. Since each bit position can be a 0 or a 1,''' °
'''there are 256 possible 8 bit patterns 00000000 00000001 ... up to'' °
' °
'''11111110 11111111. For each of these patterns, there is associated' °
'' °
'''a special character. The entire sequence can be displayed with a''' °
'''SYSTEM VARIABLE called the ATOMIC VECTOR'',r' 'show ''ÉAV''' °
'''(Note: The 14th character does not print, but causes a carriage ret °
urn)'',r' °
'''The following table gives the location of these 256 characters (not °
e''' °
'''however that blanks are fond in positions 1,14,33 and 256)'',r' °
'av' 'do' °
'''The box (É), followed by specific keywords has been reserved by APL °
2''' °
'''for SYSTEM FUNCTIONS and SYSTEM VARIABLES. These are not strictly p °
art''' °
'''of the APL2 language, but provide access to the non-APL2 environmen °
t.'',r' °
'''We will study these in due time. Meanwhile note that evaluation''' °
'''of ÉAV produces a listing of all special characters that are''' °
'''available to the APL2 user.''' 'do' °
'''But coming back to dyadic sort, unless you have reasons to need''' °
'''alternate collating sequences, the following idiom should''' °
'''produce a reasonable sort vector'',r' 'show ''TEXT[ÉAV√TEXT]''' °
'''Alphabetic sort (or alpha sort) will work on arrays as well'',r' °
'show ''NOS╜''''ONE'''' ''''TWO'''' ''''THREE'''' ''''FOUR'''' ''''FIV °
E'''' ''''SIX'''' ''''SEVEN''''''' °
'show ''NOS╜πNOS'' ''NOS'' ''NOS[ÉAV√NOS;]''' °
'''There is, however one problem with sort when using the atomic vecto °
r.''' '''suppose that our text also includes lower case words'',r' °
'show ''NOS╜π(Γ[2]NOS),''''eight'''' ''''nine'''' ''''ten'''' ''''elev °
en'''' ''''twelve''''''' 'show ''NOS[ÉAV√NOS;]''' °
'''Clearly this is NOT adequate. What we need is a way to recognize th °
at''' '''a and A are equivalent. We could try the following'',r' °
'show ''ALPHA╜''''aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ °
''''''' 'show ''NOS[ALPHA√NOS;]''' °
'''In this approach, a lower case letter does not have the same value °
as''' °
'''an upper case letter. Lower case letters will sort in front of uppe °
r''' °
'''case letters. Because of that, the words THREE and TWO sort behind °
the''' °
'''words ten and twelve. A better way is to define the sort sequence a °
s''' °
'''an array. In an array, ALL non blank elements in a column are treat °
ed''' '''as equivalent in a sort sequence.'',r' °
'show ''A╜π''''abcdefghijklmnopqrstuvwxyz'''' ''''ABCDEFGHIJKLMNOPQRST °
UVWXYZ''''''' 'show ''A'' ''NOS[A√NOS;]''' °
'''If the left argument to grade does not contain all symbols in the'' °
' °
'''right argument, the missing symbols have a default value greater th °
an''' '''the last symbol in the left argument'',r' °
'show ''STRING╜''''The age is 34, weight 195.3.'''''' ''STRING[ALPHA√S °
TRING]''' °
'''Note that the non-alpha characters maintain their original sequence °
.''' 'do' °
'''Before we leave the dyadic sort, we should describe techniques for' °
'' °
'''using the atomic vector. As its name implies, the atomic vector is' °
'' °
'''an APL2 vector. It is not like other arrays, because it is constant °
''' '''and cannot be assigned values'',r' °
'show ''µÉAV'' ''ÉAV╜''''ABCD'''''' ''µÉAV''' °
'''Since it is a vector, we can access any of its scalar elements'',r' °
'show ''ÉAV[3+∞4]'' ''ÉAV∞''''TEXT'''''' ''ÉAV[85 70 89 85]'' ''ÉAV[32 °
+85 70 89 85]''' °
'''Any special symbol not available from the keyboard can in this way' °
'' °
'''be obtained and used to advantage. There are some characters in ÉAV °
''' °
'''that do not have a visible representation. These characters produce °
''' °
'''effects related to the pressing of grey keys on your keyboard, such °
X''' '''as BACKSPACE, NEWLINE, LINEFEED, ...''' 'endd' °
*(1997 6 10 13 10 56 448) °
FTEACH5 ÉFX 'TEACH5' 'Σ System functions and variables' °
'exit ''TEACH5''' °
'''In addition to ÉAV, the IBM version of APL2 supports a number of''' °
'''other System Functions and System Variables. For the time being,''' °
'''we will describe only two of these.'',r' °
'''The SYSTEM VARIABLE called TEMINAL CONTROL CHARACTERS is a three''' °
'''element vector. In some versions of APL2 all three elements have''' °
'''meaning: BACKSPACE TO LEFT, NEW LINE (RETURN), and LINE FEED. In th °
e''' °
'''current version of APL2OS2 only the NEW LINE (RETURN) works. The ot °
her''' °
'''"terminal control" characters wil display special symbols on the sc °
reen'',r' °
'show ''ÉTC[1 3]'' ''''''Backspace'''',ÉTC[1],''''and line feed'''',ÉT °
C[3],''''fails''''''' °
'''The NEW LINE control character will cause text (or numbers) to''' °
'''coninue displaying on a new line'',r' °
'show ''(∞10),ÉTC[2],(10+∞10)'' ''''''CONTINUE'''',ÉTC[2],''''ON A NEW °
LINE''''''' °
'''An example of a SYSTEM FUNCTION is ATOMIC FUNCTION represented by'' °
' °
'''ÉAF. This function is closely related to the usage of ∞ with ÉAV'', °
r' °
'show ''ÉAV∞''''TEXT'''''' ''ÉAF ''''TEXT'''''' ''ÉAV[3+∞4]'' ''ÉAF 2+ °
∞4''' °
'''Note that ÉAF behaves as if counting integers begin with 0 instead' °
'' °
'''of with 1. This way of counting is called ZERO INDEX ORIGIN. We wil °
Xl''' '''learn more about that later.''' 'endd' °
*(1997 6 12 12 44 31 488) °
FTEACH6 ÉFX 'TEACH6' 'Σ System commands' 'exit ''TEACH6''' °
'''In addition to System Functions and Variables, there are also''' °
'''SYSTEM COMMANDS. You are already familiar with two of these'',r' °
''' )LOAD workspace''' ''' )OFF''' 'do' °
'''Unlike the first two, System Commands cannot be used inside APL2''' °
'''expressions. System Commands lie entirely outside APL2, and are''' °
'''used to describe or manipulate the APL2 session and environment.'', °
r' '''We will list here only those that are currently appropriate'',r' °
'''It should be pointed out that as long as you are under the control' °
'' °
'''of this session, any attempt to issue these commands will fail.''' °
'''This is because the lesson assumes that any input by you is a valid °
''' °
'''APL2 expression. To test these commands, wait until the end of the' °
'' '''lesson, or enter EXIT.''' 'do' ''' )WSID'',r' °
'''This command will return the name of current workspace (TEACH9).''' °
'do' °
'''Any of these workspaces can be made active by issuing the command'' °
,r' ''' )LOAD workspace-name''' 'do' ''' )LIB'',r' °
'''This command will list the names of all workspaces in the library.' °
'' °
'''The words LOAD and LIB can be followed by a library number. (You ca °
n''' °
'''define library numbers by adding to your APL2 Invocation command fi °
le.''' °
'''The process is described in a separate tutorial dealing with APL2OS °
2.)''' 'do' ''' )OFF'',r' °
'''This command will quit APL2, and return you to the environment''' °
X '''from which you entered APL2.''' 'endd' °
XNVECTOR 1 20 7 7 38 38 23 23 27 27 11 11 3 3 34 34 34 34 47 47 20 20 °
*(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 52 33 548) °
Ferase ÉFX 'erase;t;EXIT;GO;HELP;DISPLAY;REVIEW;BIND;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 4 16 248) °
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' °