home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH16A.ATF
< prev
next >
Wrap
Text File
|
1997-09-19
|
56KB
|
683 lines
XNÉIO 0 1 °
XNÉCT 0 1E²13 °
XCÉFC 1 6 .,*0_² °
XNÉRL 0 16807 °
XCÉPR 1 1 °
XCÉLX 1 5 TEACH °
*(1996 4 6 16 9 6 228) °
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 7 8 13 23 39 428) °
FCOMMANDS ÉFX 'COMMANDS' 'Σ Summary of System commands' °
''' )CHECK Obtain diagnostic information''' °
''' )CLEAR Reset to a blank workspace called CLEAR''' °
''' )CONTINUE Save in workspace CONTINUE with suspensions' °
'' °
''' )COPY ws obj1[obj2] Copy from workspace ''''ws'''' APL2 object[s °
] ''''obj*''''''' °
''' )DROP wsid Remove ''''wsid'''' from library (same as DO °
S ERASE)''' °
''' )EDITOR # Select APL2 editor (only 1 in APL2OS2)''' °
''' )ERASE object Remove named object from workspace''' °
''' )FNS List all defined functions in workspace''' °
''' )HOST Submit OS2/dos command''' °
''' )LIB [#] Lists all workspaces [in library #]''' °
''' )LOAD ws Load workspace ''''ws''''''' °
''' )MORE Obtain more information on error message''' °
''' )NMS List ALL APL2 objects in workspace''' °
''' )OFF Logs you off from APL2. Returns to DOS''' °
''' )OPS List all uder defined operators''' °
''' )OUT name Save workspace in ATF format''' °
''' )PCOPY name [name] Copy only object not already in workspace''' °
''' )PIN name [name] Copy from ATF file object not already in wor °
kspace''' ''' )RESET [#] Clear State Indicator''' °
''' )SAVE Store workspace in a file (wsid.TRY in TRYAP °
L2)''' °
''' )SAVE name Store workspace in file ''''name.TRY''''''' °
''' )SI (Returns blank in TRYAPL2)''' °
''' )SIC Synonym of )RESET''' °
''' )SINL List state indicator with name list''' °
''' )SYMBOLS [#] List/Specify nimber of symbols in symbol tab °
le''' °
''' )VARS List all variables currently active in works °
pace''' °
''' )WSID Supply the name of current workspace''' °
X ''' )WSID wsid Rename current workspace ''''wsid''''''' °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1996 4 6 16 9 6 228) °
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 9 6 228) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1996 4 6 16 9 6 228) °
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 9 8 12 23 46 460) °
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' °
'''COMMANDS Summary of System Commands''' °
X '''BIND A listing of binding rules''' 'endd' °
*(1997 9 7 13 23 5 296) °
FTEACH ÉFX 'TEACH' 'Σ Start lesson #16: APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' 'TEACH1 Σ System commands' °
'TEACH2 Σ Index origin' 'TEACH3 Σ Local and global variables' °
'TEACH4 Σ Adopting conventions' °
'TEACH5 Σ Sample utility functions "do"''' °
'TEACH6 Σ Utility functions "show" and "showfn"' °
X 'TEACH7 Σ System functions and System variables' 'problems' °
*(1997 7 9 14 11 40 392) °
FTEACH1 ÉFX 'TEACH1' 'Σ Discuss System Commands' °
'''In the previous lesson we saw examples of nested data structures''' °
'''and their use. We defined a number of functions that performed''' °
'''interesting tasks. We also learned about APL2 idioms, and how one'' °
' °
'''can find specific idioms with workspace IDIOMS provided by IBM.''' °
'do' ''' SYSTEM COMMANDS'',r' °
'''In this lesson we will study SYSTEM COMMANDS. These are expressions °
''' °
'''that begin with a right parenthesis. System commands are NOT part o °
f''' °
'''the APL language and cannot be included in user defined functions.' °
'' °
'''When you enter these commands such as )LOAD ... it is not the APL'' °
' '''processor that evaluates them. Instead the ")" tells the APL''' °
'''processor to transfer the expression to the system under which APL' °
'' '''is evaluated.''' 'do' °
'''Before we introduce new (and old) System commands, heed this warnin °
g!'',r' °
''' WHILE IN THIS LESSON, YOU CANNOT ISSUE SYSTEM COMMANDS.''' °
''' ON COMPLETION OF THE LESSON YOU MAY PRACTICE, BUT BE SURE''' °
''' TO HAVE BACKUP COPIES OF ALL TEACH* WORKSPACES. IF YOU''' °
''' ARE CARELESS, YOU MAY EASILY DESTROY YOUR SOFTWARE.'',r' °
'do' °
'''You should be already quite familiar with the following commands,'' °
,r' ''' )LOAD workspace --or )IN workspace''' °
''' )OFF''' °
'''We will introduce here many, but not all System Commands available °
to APL2''' 'do' ''' WORKSPACE NAME'',r' °
'''Once a workspace is loaded, you can rename it by''' °
''' )WSID newname''' °
'''If you have forgotten the current name of the workspace, then )WSID °
''' '''with no argument will provide that name.''' 'do' °
''' COPYING FROM A WORKSPACE FILE'',r' °
'''If you desire to copy into the active workspace the contents of all °
or''' °
'''only a few selected APL2 objects (variables, functions or operators °
)''' '''then enter''' ''' )COPY ws''' °
''' )COPY ws object1 [object2 ..]''' °
'''In the first form, all objects from the named workspace will be cop °
ied''' °
'''into the currently active workspace. In the second form, only the'' °
' °
'''named objects will be copied. (The brackets indicate that you may c °
opy''' '''more than one object at a time.)''' °
'''If the workspace to be copied is in the ATF format (ATF stands for °
"APL''' '''Transfer Format"), then the commands should be''' °
''' )IN ws''' ''' )IN ws object1 [object2 ..]''' °
'''If you wish to copy from a workspace in such a way that currently a °
ctive''' °
'''objects are NOT over-riden, then the corresponding commands are''' °
''' )PCOPY ws''' ''' )PIN ws''' °
''' )PCOPY ws object1 [object2 ..]''' °
''' )PIN ws object1 [object2]''' °
'''To find out what workspaces are available, enter''' °
''' )LIB [#]''' °
'''If a library # is given, only the workspaces stored in that library °
''' °
'''will be listed. To see the contents of your private library, enter' °
'' '''just )LIB.''' 'do' ''' SAVING A WORKSPACE'',r' °
'''To store an active workspace, you can enter''' ''' )SAVE''' °
''' WARNING! ANY PREVIOUS WORKSPACE WITH THIS NAME WILL BE LOST!' °
',r' °
'''If you wish to store the workspace under another name, you may ente °
r''' ''' )SAVE wsid''' °
'''If you wish to save the active workspace in the ATF format, then en °
ter''' ''' )OUT ws''' °
'''On occasion you may wish to temporarily save a workspace in such a °
way''' °
'''that on entering APL2 the next time, that same workspace will be''' °
'''automatically re-loaded, and any interrupted execution can be resum °
ed.''' '''To do that, enter''' ''' )CONTINUE''' 'do' °
''' DELETING APL2 OBJECTS'',r' °
'''If you decide to erase one or more APL2 objects from the workspcae, °
''' '''you can enter''' ''' )ERASE object1 [OBJECT2 ..]''' °
'''You can also delete an entire workspace''' °
''' WARNING! The following command should be used with caution.'' °
' ''' If in doubt, maintain adequate backup.''' °
''' )DROP workspace''' °
'''This command eliminates a workspace. It is equivalent to the DOS''' °
'''command: ERASE file''' °
'''If you want to erase your active workspace then enter''' °
''' )CLEAR''' '''The workspace name becomes CLEAR''' 'do' °
''' CONTENTS OF ACTIVE WORKSPACE'',r' °
'''To find out what objects exist in the workspace, there are four''' °
'''Systems commands: )NMS, )VARS, )FNS and )OPS. )NMS will list ALL''' °
'''objects in the workspace. The name is followed by a period and an'' °
' °
'''integer: (2=variable, 3=function, 4=defined operator). )VARS will'' °
' °
'''list only the names of active variables. )FNS will list only define °
d''' '''functions, and )OPS will list all defined operators.''' 'do' °
''' EXECUTION STATUS'',r' °
'''If you have interrupted the execution of a defined function, that'' °
' °
'''execution remains in suspension. You can find out the status by''' °
''' )SI''' ''' )SINL --or''' ''' )SIS''' °
'''These commands will produce a listing of suspended functions. To''' °
'''re-enter the execution, you can branch to the line number of the''' °
'''first (top) line of the list'',r' °
'''To remove suspended execution, you can enter''' °
''' )RESET # --or its synonym-- )SIC #''' °
'''If a number is given, only the number of most recent suspensions wi °
ll''' '''be removed from the top of the state indicator list.''' 'do' °
''' OTHER SYSTEM COMMANDS'',r' °
'''If you get an error message, there is a command you can give to obt °
ain''' '''more information''' ''' )MORE''' °
'''Most (if not all) of the time APL2OS2 will print: NO MORE INFORMATI °
ON''' 'do' ''' )HOST (OS2-dos)-command''' °
'''The above expression allows you to send a message to the operating' °
'' °
'''system (e.g. "dir a:"). To see the results, however, you have to''' °
'''press Ctrl-ESC and select the APL2OS2 window.''' 'do' °
'''If you have problems with the execution, you might try''' °
''' )CHECK ... --see Language reference for options''' 'do' °
'''If you get a message that your SYMBOL TABLE is full, you can invoke °
''' ''' )SYMBOLS [size]''' 'do' °
'''Some other System Commands are not listed here because they have''' °
'''meaning only in non-PC APL2 software.''' °
'''To see all available System commands, enter COMMANDS. This function °
X''' '''tabulates all System commands supported by APL2OS2.''' 'endd' °
*(1997 7 10 12 23 55 496) °
FTEACH2 ÉFX 'TEACH2;FOO;VAR' 'Σ Index origin' °
''' INDEX ORIGIN'',r' °
'''If you decide to use functions developed by someone else, then it i °
s''' °
'''only natural to inquire whether those functions (or operators) are' °
'' °
'''compatible with yours. There is one major source of incompatibility °
.''' °
'''It is a System Variable called the INDEX ORIGIN (ÉIO). ÉIO may be'' °
' '''assigned a boolean value.''' 'do' °
'''Up to now we have been using index origin 1. This means that the co °
unt''' °
'''begins with 1. Some programmers prefer to begin counting with 0'',r °
' 'show ''∞5'' ''ÉIO╜0'' ''∞5'' ''ÉIO╜1''' °
'''Using one index origin on data (or functions) defined in another''' °
'''index origin can lead to problems'',r' °
'show ''ÉIO'' ''(∞5)[5]'' ''ÉIO╜0'' ''(∞5)[5]'' ''(∞5)[4]'' ''ÉIO╜1''' °
'''If software development is done in an environment where defined''' °
'''functions are "borrowed" from other applications, then precautions' °
'' '''should be taken to avoid such conflicts.''' 'do' °
'''How does one do that?'',r' °
'''One way would be to define index origin as a local variable, and se °
t''' '''it to whatever is the desired value:'',r' °
'show ''ÉFX ''''FOO W;ÉIO'''' ''''Σ Index Origin is local'''' ''''ÉIO╜ °
0'''' ''''∞W''''''' '1 showfn ''FOO''' 'show ''∞5'' ''FOO 5'' ''∞5''' °
'''Another way is to make sure that expressions are "index origin''' °
'''independent":'',r' °
'show ''VAR╜∞5'' ''ÉIO╜0'' ''VAR[ÉIO+0 2]'' ''ÉIO╜1'' ''VAR[ÉIO+0 2]'' °
' °
'''In this expression no matter what the index origin, the contents of °
''' '''brackets return the first and third element of VAR.''' 'do' °
'''The problem of index origin seldom comes up in practice. But when i °
t''' °
'''does, it may be very baffling. To see this, just set the index orig °
in''' °
'''to zero, exit from this lesson, and re-enter it with TEACH.''' °
'do' °
'''If you write code for use by other APL2 programmers, it is good adv °
ice''' °
'''to make it ÉIO independent. On the other hand, if you write APL2 co °
de''' °
'''mostly for yourself, it may not be worth the extra effort. As a mat °
ter''' °
'''of fact, the majority of APL2 programmers appear to use index origi °
n''' °
'''of ONE. On the other hand J programmers are limited to index origin °
X 0.''' 'endd' °
*(1997 7 10 12 53 6 420) °
FTEACH3 ÉFX 'TEACH3;MEANING' 'Σ Discuss the role of global variables' °
''' USING GLOBAL VARIABLES'',r' °
'''Another source of potential problems comes from the use of GLOBAL'' °
' '''VARIABLES. The advantage of having global variables is their''' °
'''availability to all defined functions. This can also be a great''' °
'''disadvantage.'',r' °
'''How does one decide what variables should be global?''' 'do' °
''' 1. There may be variables to define the workspace environment:'' °
,r' °
'''If some functions are sensitive to the hardware setup, then it migh °
t''' °
'''be a good idea to place this information into one or more globals.' °
'' °
'''For example, in some applications it is important to know the name °
of''' '''the partition (C:, D:...) where certain files reside.''' 'do' °
''' 2. Another reason for storing data in a globals is if it is''' °
''' frequently referenced, by several functions.'',r' °
'show ''dig'' ''lc'' ''uc''' °
'''Variables ''''dig'''', ''''lc'''' and ''''uc'''' contain numeric di °
gits, lower''' °
'''and upper case letters. These characters could be extracted from th °
e''' '''atomic vector, but dig, uc and lc is easier to remember''' °
'do' °
''' 3. Some special symbols may not be readily accessible from the'' °
' ''' keyboard'',r' °
'''Look at the left hand tabulations of symbols when you select the''' °
'''"Modify keyboard" from the Options pull down menu.''' 'do' °
''' 4. When a variable is passed to a function as a right or left''' °
''' argument, a separate copy may have to be made. If that''' °
''' variable takes up a great deal of storage, valuable resources °
''' ''' may be wasted.'',r' °
'''We saw an example of that when we defined a rule based Expert Syste °
m.''' °
'''We stored nested arrays ANTE, CONS, FACTS and GOALS as globals.''' °
'do' °
'''Working with globals also causes problems. For example, suppose we °
''' °
'''decide to name a global: X. Then if a defined function names X as' °
'' °
'''local, the global name is not accessible to that function. This may °
''' °
'''not only lead to trouble, but also to difficulties in figuring out °
what''' '''is wrong when things do not work the way we expect them.''' °
'do' °
'''Another problem comes up when a utility is copied into a workspace. °
''' °
'''If that utility calls on global variables or functions either not i °
n''' °
'''the workspace or incompatible, then there will be problems. One''' °
'''solution to these problems is to adopt simple and reasonable naming °
X''' '''conventions.''' 'endd' °
*(1997 7 10 13 21 35 412) °
FTEACH4 ÉFX 'TEACH4' 'Σ Using conventions' '''ADOPTING CONVENTIONS'',r' °
'''One problem with conventions is that not everyone uses the same one °
s.''' °
'''If you build your own applications, it is always a good idea to hav °
e''' '''some sort of naming conventions.''' 'do' °
'''For example in these lessons, all utility functions (and operators) °
''' °
'''as well as all global variables have been defined as lower case nam °
es.''' °
'''Here is an example on how you may take advantage of that convention °
.''' °
'''Suppose you wish to develop a new workspace, and wish to use all''' °
'''previously available utilities. You can load an existing workspace' °
'' '''containing the following utility'',r' '1 showfn ''erase''' 'do' °
'''Ignoring for now the upper case labels in the header, the function' °
'' '''invokes the system command ÉNL which stands for Name List'',r' °
'show ''Γ[2]ÉNL 2''' °
'''In the example, the right argument of 2 calls for a list of all''' °
'''global variables (as well as any local variables in the currently'' °
' °
'''active function). A 3 would list all functions, and a 4 would list' °
'' '''all defined operators.'',r' °
'''Function "erase" first generates a list of all functions.''' °
'''Then it erases (using ÉEX) all but those that are in lower case.''' °
'''It repeats the process for all variables and all defined operators. °
'',r' °
'''What you have left in the workspace is only the utilities (and you' °
'' '''better rename the workspace before you save it).''' 'do' °
'''Actually, in the sample function, there are additional features.'', °
r' °
''' 1. All functions beginning with the word TEACH are also saved'',r' °
''' 2. All names listed in the header are made local, and therefore''' °
''' will not be listed with ÉNL.'',r' °
'''With these two schemes it is possible to clean out a TEACH workspac °
e''' °
'''of any sample functions or variables generated by a student. (This °
is''' °
'''why at the start of each tutorial, a message requests the student t °
o''' '''press the Caps Lock key.)''' 'do' °
'''A given set of conventions may not be adequate for everyone. For''' °
'''example, Harry Bertucelli''''s workspaces distinguished user define °
d''' °
'''functions from user defined operators. Functions were named in uppe °
r''' °
'''case and operators in lower case. In early versions of APL, defined °
''' °
'''functions were documented in functions of the same name, but with'' °
' °
'''the added ending HOW. Whatever conventions are adopted, it is a goo °
d''' °
'''idea to have a workspace, a global variable, or a niladic function' °
X'' '''that explains these conventions.''' 'endd' °
*(1997 7 10 13 25 2 296) °
FTEACH5 ÉFX 'TEACH5;A' 'Σ Describe three utility functions' °
'''Let us take a look at other utility functions in this workspace. We °
''' °
'''begin with function "do". This function simulates the APL2 prompt,' °
'' '''and accepts valid APL2 expressions as well as well as Direct''' °
'''Definitions (which are not valid under APL2).''' 'do' °
'1 showfn ''do''' 'do' °
'''Lines [3] and [4] simulate the effect of APL when waiting for user' °
'' °
'''input. This input is captured, and if it contains only blanks [5], °
the''' °
'''function exits. If the expression contains a colon [6], consider it °
to''' °
'''be a direct definition. Evaluate the expression with a utility func °
tion''' °
'''called "evaldd". Otherwise attempt to evaluate it using the ÉEA''' °
'''System Function. If this succeeds, return to line [2] to capture''' °
'''another expression from the keyboard.''' 'do' °
'''If the attempt fails, capture the error message in local variable E °
,''' '''and display the message'',r' °
''' This is not a valid APL2 expression''' ''' *'',r' °
'''If the next keyboard entry is a ?, then the error message (in E) wi °
ll''' °
'''be displayed. Else the function returns to the next APL2 prompt.''' °
'do' °
'''Function "do" is used within the lessons to allow the student''' °
'''to enter APL2 expressions without interrupting the tutorial.''' °
X 'endd' °
*(1997 7 10 13 47 32 504) °
FTEACH6 ÉFX 'TEACH6' 'Σ Function show and showfn' °
'''There are two more utility functions of interest: "show" and''' °
'''"showfn". The first function simulates a keyboard entry''' °
'''followed by the result of that entry. It is used in the lessons to' °
'' °
'''display examples under discussion. Function "showfn" displays a''' °
'''user defined function as if it were requested with the Del mode.'', °
r' '''Here is the listing of these two functions.''' 'do' °
'1 showfn ''show''' 'do' '1 showfn ''showfn''' 'do' °
'''NOTE: These two functions invoke "doif" a utlity that was designed' °
'' °
'''under TRYAPL2 at a time when the diamond (╪) was not available. You °
''' °
'''may also look at this utility. I have left it in place partially''' °
'''because it does not do any harm. In execution it is 2⌡slower than'' °
' '''the diamond''' 'do' °
'''Now, evaluate the following two expressions:'',r' °
''' show ''''∞5'''' and'',r,'' 1 showfn ''''addquote'''''',r' °
'''Can you explain the purpose of the left argument to showfn?''' °
X 'endd' °
*(1997 9 19 12 39 30 504) °
FTEACH7 ÉFX 'TEACH7' 'Σ System Functions and System Variables' °
''' SYSTEM FUNCTIONS AND SYSTEM VARIABLES'',r' °
'''There are several System functions and System variables that''' °
'''provide information and functionality to APL2. We will list here''' °
'''those that appear to be supported by APL2OS2. (For additional ones, °
''' '''see the language reference manual.)'',r' °
''' LATENT EXPRESSION'',r' °
'''When you load a workspace such as one of these tutorials, the lesso °
n''' °
'''begins without any prompting by you. This happens because on loadin °
g''' °
'''the workspace, an APL2 expression has been defined as LATENT''' °
'''with the command ÉLX'',r' 'show ''ÉLX''' °
'''The latent expression "TEACH" has been defined on all workspaces of °
''' °
'''this tutorial; however for workspaces UTILITY and INDEX it is "lx". °
''' °
'''When a workspace is retrieved using the ")IN ..." system command,'' °
' °
'''the latent expression, if it exists, is also retrieved but is not'' °
' '''evaluated.''' 'do' °
''' INFORMATION ABOUT THE WORKSPACE ENVIRONMENT'',r' °
'''There are several System functions and System commands that give''' °
'''information about the APL2 session, and about the workspace:'',r' °
'''ACCOUNT INFORMATION (ÉAI) is a variable that cannot be assigned. It °
''' °
'''gives information about the user identification (1001 if only one'' °
' °
'''APL2 session is active), compute time, duration of the session, and °
''' '''user response time. (Times are in miliseconds)'',r' °
'show ''ÉAI''' °
'''COMPARISON TOLERANCE (ÉCT) is a variable. Its contents (default is' °
'' °
'''1E²13) determine whether two quantities will be treated as the same °
.''' °
'''It is also used in other contexts to determine whether a value shou °
ld''' '''treated as an integer'',r' °
'show ''2=2+1E²14 ╪ 2=2+1E²12 ╪ 2+1E²14''' °
'''DELAY (ÉDL) is a function. The right argument is the number of seco °
nds.''' °
'''APL2 processing is suspended for that length of time. The function' °
'' '''returns the time of suspension.'',r' 'show ''ÉDL 2''' °
'''PRINT PRECISION (ÉPP) is a variable. Its value (default is 10)''' °
'''determines the number of significant digits to be displayed'',r' °
'show ''ÉPP ╪ *1 ╪ ÉPP╜16 ╪ *1 ╪ ÉPP╜5 ╪ *1 ╪ ÉPP╜10''' °
'''PRINTING WIDTH (ÉPW) is a variable. In the options pull down menu, °
you''' °
'''can select under "Font" the font size. The available ranges are''' °
'''8,10,(12),14,18,24. You can accomodate the printing width of APL2 t °
ext''' '''using this variable. Default is 79.'',r' °
'show ''ÉPW ╪ ÉPW╜30 ╪ 40µuc ╪ ÉPW╜120 ╪ 120µuc ╪ ÉPW╜79''' °
'''WORKSPACE AVAILABLE (ÉWA) is a variable that cannot be set. When''' °
'''invoked, it gives the number of free bytes available in the workspa °
ce'',r' 'show ''ÉWA''' °
'''Other System functions and variables are described in separate tuto °
rials''' °
X '''dealing with Shared Variables and Auxilliary Processors.''' '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 18 12 43 8 424) °
Ferase ÉFX °
'erase;t;EXIT;GO;HELP;DISPLAY;BIND;REVIEW;RULE;COMMANDS;DISCLAIMER' °
'Σ Erase all extraneous global functions and variables' 't╜ÉNL 3' °
't╜(~t^.εlc,'' '')≡t' 't╜ÉEX(~t[;∞5]^.=''TEACH'')≡t' 't╜ÉNL 2' °
X 't╜ÉEX(~t^.εlc,'' '')≡t' 't╜ÉNL 4' 't╜ÉEX(~t^.εlc,'' '')≡t' °
*(1997 7 27 13 47 41 608) °
Fevaldd ÉFX 'u╜evaldd w;c;n' 'Σ Evaluate direct definition' 'u╜0' °
'n╜(w∞''Σ'')-1' 'c╜(((n╞w)⌠'':'')Γn╞w),Γ''ΣDD '',(n+1)╟w' °
'╕((1 label╞c)doif ''''''Invalid label'''''')/0' °
'╕((2=µc)doif ''u╜showdd 1╙c'')/0' °
'╕((3=ÉNC╞c)doif ''u╜⌡µÉ╜(╞c),'''' is already defined.'''''')/0' °
'╕((3=µc)doif ''u╜simdd c'')/0' 'c╜(Γ''α∙ aw'')replace■c' °
'u╜ε''u╜'',((''a''εεc[2 3 4])/''a ''),(╞c),'' w;t;b''' °
'u╜u(5πc)(''b╜(t╜'',(3πc),'')/'',addquote ''u╜'',4πc)' °
X 'u╜u,''╕(t doif b)/0''(''u╜'',2πc)' 'u╜╧ÉFX u' °
*(1997 7 25 13 27 52 564) °
Fexit ÉFX 'V exit W;T' 'Σ Exit if too many suspended functions' °
'╕(0⌠ÉNC ''V'')/L0 ╪ V╜10' 'L0:╕(V>µÉLC)/0' °
'''There are too many suspended functions''' '''Please enter '',W' °
X '╕' °
*(1997 7 26 12 33 39 536) °
Fget ÉFX 'U╜V get W;t;T;ÉPR' 'Σ Prompt for response from keyboard' °
'ÉPR╜T╜ÉAV[ÉIO+255] ╪ ╕(0⌠ÉNC ''V'')/L0 ╪ V╜1' 'L0:V╜V╧1' 'æ╜W ╪ t╜æ' °
'U╜(+/^\t=T)╟t' '╕(''╕''⌠╞U)/L1 ╪ ╕' 'L1:╕V/0' 't╜(U⌠'' '')ΓU' °
X 'U╜(µt),(ΓU),t' °
*(1997 7 28 13 33 8 424) °
Fglobals ÉFX 'globals' 'Σ Initialize useful global variables' °
'uc╜''ABCDEFGHIJKLMNOPQRSTUVWXYZ''' °
'lc╜''abcdefghijklmnopqrstuvwxyz''' 'dig╜''1234567890''' °
X 'r╜ÉAV[13+ÉIO]' 'q╜''''''''' °
*(1997 7 3 12 47 6 368) °
Finitialize ÉFX 'initialize;T' 'Σ Initialize workspace' °
'''AT ALL TIMES, TO CONTINUE, PRESS RETURN!'',r' °
'''To see disclaimers enter:'',r,'' disclaimer''' 'do' 'erase' °
'globals' °
'''Make sure the CAP LOCK light on your keyboard (upper right) is ON!' °
X'' 'endd' °
*(1997 7 27 13 14 33 444) °
Flabel ÉFX 'u╜v label w' °
'Σ Return 1 if label w does not begin with a cap' °
'╕(0⌠ÉNC ''v'')/L0 ╪ v╜0' 'L0:v╜v╧1 ╪ w╜εw ╪ ╕v/L1 ╪ ╕(u╜0⌠ÉNC w)/0' °
X 'L1:╕(u╜~^/wεlc,uc,dig)/0' 'u╜w[1]εlc,dig' °
XClc 1 26 abcdefghijklmnopqrstuvwxyz °
*(1997 7 13 12 28 55 528) °
Fnon ÉFX 'non;T;RC;ET;R' 'Σ Ignore keyboard entry' 'æ╜'' ''' 'T╜æ' °
'╕(0=µ(T⌠'' '')/T)/0' '(RC ET R)╜ÉEC T' '╕(0=RC)/2' °
X '╕((1=RC)doif ''R'')/2' '╕2' °
*(1997 7 13 12 28 55 528) °
Fnotb ÉFX 'u╜notb w' 'Σ Remove trailing blanks' °
'╕((1<╧w)doif ''u╜notb■ w'')/0' '╕((1<µµw)doif ''u╜πnotb Γ[2]w'')/0' °
X 'u╜(1-(,'' ''⌠Φw)∞1)╟w' °
*(1997 7 27 12 55 6 496) °
Fproblems ÉFX 'problems' 'Σ Problems' °
'''That is all for this lesson. Remember, if you want to practice,''' °
'''and plan to use direct definitions, be sure to first enter GO.''' °
'''Direct definitions will then be accepted. To exit GO, enter EXIT.'' °
,r' °
'''To erase a previously defined DIRECT DEFINITION FUNCTION, enter'',r °
' ''' )ERASE functionname'',r' °
X '''WARNING! do not use )ERASE on other labels.'',r' °
XCq 0 ' °
XCr 0 °
*(1997 7 13 12 28 56 532) °
Freplace ÉFX 'u╜v replace u;i;r;s' 'Σ Replace elements in v in u' °
'i╜Γ∞µu' 's╜2πv╜(v⌠'' '')Γv' 'i╜⌡r╜i⌡■Γ[1]u°.=╞v' °
X 'u[(εi)/εr]╜s[(εi)/εi⌡■∞µs]' °
*(1997 7 13 12 28 56 532) °
Fround ÉFX 'U╜V round W' 'Σ Half adjust to V th decimal' °
X 'U╜(╛0.5+W⌡10*V)÷10*V' °
*(1997 7 13 12 28 57 536) °
Fshow ÉFX '╢V show ╢W;╢T;╢B' 'Σ Display and execute ╢W' °
'╢T╜(0=ÉNC ''╢V'')doif ''╢V╜0''' °
'╕((0=╧╢W)doif ''show ╢W,'''' '''''')/0' °
'╕((1<╧╢W)doif ''╢V show ■╢W'')/0' ''' '',╢W' °
X '╕((╢V^'':''ε╢W)doif ''╢T╜evaldd ╢W'')/L0' '''ÉEM'' ÉEA ╢W' 'L0:do' °
*(1997 7 13 12 28 57 536) °
Fshowdd ÉFX 'u╜showdd w;a;b;c;r' °
'Σ Display a direct definition function' °
'╕((1=╧w)doif ''u╜showdd Γw'')/u╜0' °
'╕((3⌠ÉNC╞w)doif ''(ε╞w),'''' is not a function'''''')/0' °
'c╜Γ[2]ÉCR╞w' 'c╜notb(2╞c),(Γ''aw α∙'')replace■2╟c' °
'╕((~''ΣDD''╧3╞2πc)doif ''''''Not a direct definition function'''''')/ °
0' 'u╜1' 'b╜('' ''⌠╞c)Γ╞c' 'a╜'' ''' 'r╜2╟3πc' °
'╕((3=µc)doif ''a,(╞w),'''':'''',r,(3<µ2πc)/'''' Σ'''',3╟2πc'')/0' °
'a╜a,(╞w),'':'',(2╟5πc),'':''' 'b╜(+\r=''('')-+\r='')''' 'b╜b∞0' °
X 'a╜a,(²3╟(b-1)╞3╟r),'':'',2╟»(b+2)╟r' 'a,(3<µ2πc)/'' Σ'',3╟2πc' °
*(1997 7 13 12 28 57 536) °
Fshowfn ÉFX 'U╜V showfn W;F;N;T;ÉIO' 'Σ Simulate ╖W[É]' °
'T╜(0=ÉNC ''V'')doif ''V╜0''' 'ÉIO╜0' °
'U╜r,'' '',''╖'',W,''[É]'',(╞V)╞''╖''' 'N╜1╞µF╜ÉCR W' 'N╜«∞N' °
'N╜(N⌠'' '')ΓN' 'F╜(π''['',■N,■Γ''] ''),F' °
'T╜(1<µ,V)doif ''F╜F[1╟V;]'' ''U╜''''''''''' 'U╜²1╟U,r,,F,r' °
X 'U╜((-+/^\'' ''=ΦU)╟U),('' ╖'')[╞V],r' °
*(1997 7 13 12 28 58 540) °
Fsimdd ÉFX 'u╜simdd w;e' 'Σ Direct definition mode' 'u╜0' °
'╕((0⌠ÉNC╞w)doif ''''''Already defined'''''')/0' 'e╜''α''ε2πw' °
'w[2]╜Γ''u╜'',''α∙ aw'' replace 2πw' 'w╜w[1 3 2]' °
X 'w[1]╜Γε''u╜'',(e/''a ''),w[1],'' w''' 'u╜╧ÉFX w' °
*(1992 6 3 9 59 17 424) °
Ftab ÉFX 'U╜V tab W;T;A;B;C;D;E;F;G;M;ÉPW' 'Σ Tabulate list W' °
'T╜(0=ÉNC ''V'')doif ''V╜0''' 'M╜''Invalid data for tabulation''' °
'V╜4╞V' 'ÉPW╜130╛30⌐G╜V[2]+79⌡V[2]=0' °
'L1:╕((1<╧W)doif ''''''W╜∞0'''' ÉEA ''''W╜πW'''''')/L1' °
'╕(((0=µεW)δ2<µµW)doif ''U╜(~V╧4╞0)/M'')/0' °
'T╜(1≥µµU╜«W)doif ''U╜πW╜(U⌠'''' '''')ΓU''' °
'T╜(0<V[1])doif ''U╜(«(Φ1,╞µW)µ(V[3]µ'''' ''''),∞(╞µW)-V[3]),'''' '''' °
,U''' '╕(G<30)/0' 'T╜(F╜µεV[4])+C╜1╟B╜µA╜(V[3],0)╟U' °
'T╜⌐(1╞B)÷1⌐╛(ÉPW+F)÷T' 'U╜(E╜(V[3],C)╞U),[1](B╜T,1╟B)╞A' °
'''D╜εV[4]'' ÉEA ''D╜ÉAV[εV[4]+33⌡V[4]=0]''' 'L0:A╜(T,0)╟A' °
X '╕(0=1╞µA)/0' 'U╜U,(((T+V[3]),µD)µD),E,[1]B╞A' '╕L0' °
*(1997 7 13 12 28 59 544) °
Ftest ÉFX 'U╜V test W;P' °
'Σ Describe problem in W, (correct answer in V)' 'U╜2' 'L1:W' °
'É╜'' ''' 'P╜æ' '''╕L0'' ÉEA ''P╜»P''' '╕(V╧P)/0' °
X 'L0:╕(0=U╜U-1)/0' '''Incorrect. Try again''' '╕L1' °
XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ °
*(1996 4 6 16 9 6 228) °
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' °