home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teachapl.zip
/
TEACH.ZIP
/
TEACH13A.ATF
< prev
next >
Wrap
Text File
|
1997-09-19
|
71KB
|
866 lines
XNÉIO 0 1 °
XNÉCT 0 1E²13 °
XCÉFC 1 6 .,*0_² °
XNÉRL 0 1847012583 °
XCÉPR 1 1 °
XCÉLX 1 5 TEACH °
AANTE╜('1')('21=ISIN R╜EVAL P')('21<ISIN R╜EVAL P')('14 22<ISIN R')('1' °
X) °
*(1996 4 6 16 7 36 340) °
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 8 17 11 44 17 456) °
FBLACKJACK ÉFX 'BLACKJACK;D;DECK;T;S;R' °
'Σ Command for game of Blackjack' 'DECK╜∞52 ╪ DECK╜DECK[52?52]' °
'D╜''Player'' ''I win'' ''I fold'' ''Hit me'' ''I stand'' ''BLACKJACK' °
'' '╕(INFEN D)/0 ╪ T╜æ ╪ ╕(21<S╜R)/0' °
'D╜(5╞''Dealer'' ''You lose'' ''You win''),5╟D ╪ ╕(INFEN D)/0' °
X '╕(S≥R)/L0 ╪ D[2] ╪ ╕0' 'L0:D[3]' °
*(1997 8 17 11 44 21 472) °
FBLACKJACK2 ÉFX 'BLACKJACK2;D;DECK;T;S;R' °
'Σ Command for game of Blackjack' °
'DECK╜∞52 ╪ DECK╜DECK[52?52] ╪ P╜DEAL 2' °
'D╜''Player'' ''I win'' ''I fold'' ''Hit me'' ''I stand'' ''BLACKJACK' °
'' 'INFEN2 RULES ╪ T╜æ ╪ ╕(21<S╜R)/0' °
'D╜(5╞''Dealer'' ''You lose'' ''You win''),5╟D ╪ INFEN2 RULES' °
X '╕(S≥R)/L0 ╪ D[2] ╪ ╕0' 'L0:D[3]' °
ACONS╜('D[1] ''gets'' 2 ''cards:'' ╪ SHOW P╜DEAL 2 ╪ T╜æ')('D[6 2] ╪ N╜ °
²1')('D[3] ╪ N╜²1')('D[5] ╪ N╜²1')('D[4] ╪ SHOW P╜P,DEAL 1 ╪ T╜æ ╪ N╜2' °
X) °
*(1997 8 17 11 43 58 616) °
XFDEAL ÉFX 'U╜DEAL W' 'Σ Deal W cards' 'U╜W╞DECK' 'DECK╜W╟DECK' °
NDECK 1 50 13 47 6 26 21 16 2 41 29 38 52 10 40 22 4 51 33 23 30 49 3 °
14 50 45 18 37 28 8 12 36 42 11 19 44 7 31 27 24 39 1 35 17 48 25 15 °
X 20 5 32 9 43 °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1996 4 6 16 7 36 340) °
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' °
*(1997 8 17 11 44 1 392) °
FEVAL ÉFX 'U╜EVAL W;R' 'Σ Evaluate a blackjack hand' °
X 'U╜+/((∞10),3µ10)[1+R╜13|W]' '╕(~0εR)/0 ╪ U╜0¥U,(22>U+10)/U+10' °
*(1996 4 6 16 7 36 340) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1997 8 17 11 42 34 516) °
FGETNO ÉFX 'U╜V GETNO W;E' 'Σ Prompt for numeric data' °
'W ╪ U╜É ╪ ╕(0=ÉNC ''V'')/0' 'L0:╕((╞V)≤µ,U)/L1 ╪ U╜U,É ╪ ╕L0' °
'L1:U╜(╞V)╞U ╪ ╕(1=µ,V)/0 ╪ U╜(╛0.5+U⌡10*V[2])÷10*V[2]' °
'╕(2=µV)/0 ╪ V╜(4⌐µV)╞V' 'E╜(U>V[3])-U<V[4] ╪ ╕(^/E=0)/0' °
X 'V╜6╞V,V[3 4] ╪ U[(E=1)/∞µE]╜V[5] ╪ U[(E=²1)/∞µE]╜V[6]' °
*(1996 4 6 16 7 36 340) °
FGO ÉFX 'GO;T;E;B' 'Σ Expression driver' 'L0:B╜E╜''''' 'æ╜'' ''' °
'T╜æ' '╕(^/'' ''=T)/L0' '╕((^/'')OFF ''=5╞6╟T)doif ''EXIT'')/0' °
'╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/L0' °
'''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/L0' '╕B/L0' °
'''This is not a valid APL2 expression''' 'æ╜''*''' °
X '╕(''?''⌠╞1╟æ)/L0' 'E' '╕L0' °
*(1997 8 17 11 40 13 424) °
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' °
'''BIND List binding rules''' °
'''BLACKJACK Sample blackjack game''' °
X '''REVIEW Review the contents of the previous lesson''' '' 'endd' °
*(1997 8 17 11 44 14 444) °
FINFEN ÉFX 'U╜INFEN W;P;T' 'Σ Blackjack rules and logic' 'U╜0' °
'W[1],''gets'' 2 ''cards:'' ╪ SHOW P╜DEAL 2' °
'L0:╕(21⌠ISIN R╜EVAL P)/L1 ╪ W[6 2] ╪ U╜1 ╪ ╕0' °
'L1:╕(21>ISIN R)/L2 ╪ U╜1 ╪ W[3] ╪ ╕0' °
'L2:╕(~14 21<ISIN R)/L3 ╪ ΓW[5] ╪ ╕0' °
X 'L3:W[4] ╪ T╜æ ╪ SHOW P╜P,DEAL 1 ╪ ╕L0' °
*(1997 8 17 11 44 21 472) °
FINFEN2 ÉFX 'INFEN2 W;N;ANTE;CONS' 'Σ A simple Inference Engine' °
'(ANTE CONS)╜W ╪ N╜0' °
X 'L0:╕(²1=N)/0 ╪ N╜N+1 ╪ ╕(~U╜0¥»NπANTE)/L0 ╪ »NπCONS ╪ ╕L0' °
*(1997 8 17 11 44 3 400) °
FISIN ÉFX 'U╜V(f ISIN)W' 'Σ Do cards W add up to range V' 'U╜(0¥ΦV)f W' °
X '╕(1=µ,V)/0' 'U╜U^W f V[2]' °
XNNO 0 97 °
XNR 0 17 °
*(1996 4 6 16 7 36 340) °
FREVIEW ÉFX 'REVIEW;OP' 'Σ Review outer product and defined operator' °
'''In lesson 12 we inroduced a one function version of the dot operato °
r''' '''called the outer product'',r' °
'show ''(∞5)°.-∞5'' ''(∞3)°.Φ''''ABC'''' ''''CDE'''' ''''EFG''''''' °
'''When the left operand of the dot is the symbol JOT (°), the result' °
'' °
'''is an array with dimensions equal to the sum of dimensions of its'' °
' '''arguments. The elements of this result include all possible''' °
'''compositions of the two arguments'',r' °
'show ''µ(2 3µ∞6)°.⌡4 5µ∞20''' °
'''We also studied the user defined operator. This object is distingui °
shed''' °
'''from a user defined function by the presence of parentheses in the' °
'' '''header'',r' °
'show ''ÉFX ''''(f OP) W'''' ''''W°.f W'''''' ''⌡OP ∞4''' °
'''A defined operator is useful in situations where the algorithm is'' °
' °
'''independent of the function to be used. The assignment of the funct °
ion''' °
'''to be used (called binding) can be made just prior to the execution °
''' °
'''of the function. The operand(s) in a user defined operator can be'' °
' '''user defined function(s).'',r' °
'show ''ÉFX ''''U╜ODDS W'''' ''''U╜²1+2⌡∞W'''''' ''⌡OP ODDS 4''' °
X 'endd' °
ARULES╜(('1')('21=ISIN R╜EVAL P')('21<ISIN R╜EVAL P')('14 22<ISIN R')(' °
1'))(('D[1] ''gets'' 2 ''cards:'' ╪ SHOW P╜DEAL 2 ╪ T╜æ')('D[6 2] ╪ N╜² °
1')('D[3] ╪ N╜²1')('D[5] ╪ N╜²1')('D[4] ╪ SHOW P╜P,DEAL 1 ╪ T╜æ ╪ N╜2') °
X) °
*(1997 8 17 11 43 56 608) °
FSHOW ÉFX 'U╜SHOW C' 'Σ Display cards C' °
X 'U╜(3Φ''JQKA23456789'',Γ''10'')[1+13|C]' 'U╜U,■(ÉAV[6 5 4 7])[⌐C÷13]' °
*(1997 6 30 20 58 36 668) °
FTEACH ÉFX 'TEACH' 'Σ Start lesson #13: APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' 'TEACH1 Σ The quad and the quote quad' °
'TEACH2 Σ Prompting; the function GETNO' °
'TEACH3 Σ The execute primitive and the monadic format' °
'TEACH4 Σ Rndom link and time stamp' °
'TEACH5 Σ Shuffling, displaying and dealing cards' °
'TEACH6 Σ Blackjack as a production system' °
X 'TEACH7 Σ Blackjack as a rule based system' 'problems' °
*(1997 6 22 12 33 7 388) °
FTEACH1 ÉFX 'TEACH1;NO;CH;FOO;T;ÉPR' 'Σ Quad and quote quad input' °
'ÉPR╜'' ''' °
'''To refresh your memory about the previous lesson, enter REVIEW.''' °
'do' °
'''In this lessons we will study new primitive functions related to''' °
'''the process of interfacing a workspace with external devices. We wi °
ll''' '''also discuss utilities and programming strategies.''' 'do' °
'''When you enter an expression at the keyboard, you type a string of' °
'' °
'''characters. APL2 recognizes the presence or absence of leading and' °
'' °
'''trailing quotes in this string. If the quotes are present, the stri °
ng''' °
'''is returned to the screen without the quotes. If the quotes are abs °
ent,''' °
'''APL2 EVALUATES the string, and if it is a valid APL2 expression, it °
''' '''will complete the evaluation.''' 'do' °
''' THE QUAD AND THE QUOTE QUAD'',r' °
'''When APL2 is requested to display data on the screen, these are alw °
ays''' °
'''converted to a visual character representation. (Numeric data are N °
OT''' °
'''stored internally as decimal symbols.) We will now study APL2 primi °
tive''' °
'''functions that support communication between the workspace memory, °
the''' °
'''keyboard, the screen and other I/O (Input/Output) devices. We will °
also''' °
'''study APL2 primitive functions to translate between character strin °
gs''' '''and numeric arrays.''' 'do' °
'''The contents of character strings can be data or APL2 expressions.' °
'' °
'''Data can be character or numeric. We must be able to specify to APL °
2''' °
'''The nature of data that we enter at the keyboard. Here is an exampl °
e.'',r' °
'''We know how to generate numeric or character data strings'',r' °
'show ''NO╜1 (2 3) (3 3µ∞9)'' ''CH╜''''(∞4)°.⌡∞5''''''' °
'''The first expression generates a numeric nested vector. The second' °
'' °
'''expression generates a character string that also happens to be a'' °
' °
'''valid APL2 expression. Suppose now, that the contents of NO and CH' °
'' °
'''is to be determined at the keyboard by the user. APL2 has two basic °
''' °
'''keyboard entry primitive functions called QUAD and QUOTE QUAD. The' °
'' °
'''quad (É) generates a special prompt (É:) indicating that only numer °
ic''' °
'''data is to be entered. (This includes any APL2 expression that''' °
'''evaluates to a numeric array). In the following example you MUST''' °
'''enter some numbers'',r' 'show ''NO╜É'' ''2⌡NO''' °
'''The quote quad places the cursor at the beginning of the line, but' °
'' °
'''does not display a prompt. Anything you enter on that line prior to °
''' °
'''ENTER becomes part of the string. In the next example, when you see °
''' °
'''the prompt, first enter some blanks, then some characters and a few °
''' '''more blanks before pressing ENTER:'',r' 'CH╜''''' °
'show ''CH╜æ'' ''DISPLAY CH''' °
'''If you did as instructed, you will see that all blanks have been st °
ored''' '''in CH.'',r' 'do' °
'''The quad and quote quad have yet another function. When a complex'' °
' °
'''APL2 expression contains intermediate results, we can display these °
''' '''by assigning them to the quad'',r' 'show ''+/É╜3 3µ∞9''' °
'''Without the É╜ we would see only the final result. The 3 by 3 array °
''' '''is displayed in a distinct color, but not stored.'',r' 'do' °
'''Assignment to the quote quad is best illustrated with an example'', °
r' 'T╜ÉFX ''U╜FOO W'' ''æ╜W'' ''U╜æ''' '1 showfn ''FOO''' °
'''Note that ÉPR is local to function FOO.'',r' °
'show ''CH╜FOO ''''Enter anything: '''''' ''DISPLAY CH''' °
'''In function FOO, the right argument is the prompt. On line [2] this °
''' °
'''prompt is assigned to the quote quad. This causes the prompt to be' °
'' °
'''displayed on the screen and to place the cursor at the end of the p °
rompt.''' °
'''Any text entered there is returned by FOO together with a string of °
''' °
'''blanks of the same length as the prompt. In other words, the assign °
ment''' °
'''to the quote quad permits entering of character data from the keybo °
ard''' °
'''on the same line as the prompt. To work properly, the two expressio °
ns''' '''containing æ must follow immediately each other.''' 'do' °
''' PROMPT REPLACEMENT'',r' °
'''Normally, the leading prompt blanks are not desired in the result.' °
'' '''Here is one way to remove them'',r' °
'T╜ÉFX ''U╜FOO W'' ''æ╜W'' ''U╜(µW)╟æ''' '1 showfn ''FOO''' °
'show ''CH╜FOO ''''Enter anything'''''' ''DISPLAY CH''' °
'''There is a System variable called PROMPT REPLACEMENT that can be us °
ed''' °
'''to specify how to deal with the prompt. This variable is stored in °
ÉPR,''' °
'''and contains a blank as a default. ÉPR can be assigned any SINGLE'' °
' °
'''special character, or a null string. Here is an example of function °
''' °
'''FOO taking as a left argument the character to be used as a prompt' °
'' '''replacement''' °
'T╜ÉFX ''U╜V FOO W;ÉPR'' ''ÉPR╜V'' ''æ╜W'' ''U╜æ''' °
'1 showfn ''FOO''' °
'show ''CH╜''''*'''' FOO ''''Enter anything'''''' ''DISPLAY CH''' °
'show ''CH╜'''''''' FOO ''''Enter anything'''''' ''DISPLAY CH''' °
X '''A null string will retain the prompt string''' 'endd' °
*(1997 6 23 12 34 47 556) °
FTEACH2 ÉFX 'TEACH2;NAME;FN;N;T' 'Σ Quad utility' °
'''As you begin to develop APL2 applications, you will find the need t °
o''' °
'''use both the quad and the quote quad. Typically, just before asking °
''' °
'''for user input, there has to be some sort of a text statement defin °
ing''' '''the nature of data to be entered (ENTER AS REQUESTED)'',r' °
''' Enter two numbers in the range 1 to 100''' °
'show ''NO╜É'' ''2⌡NO''' ''' What is your name?''' °
'show ''NAME╜æ'' ''ΦNAME''' °
'''The need for a prompting phrase is so common that it makes sense to °
''' °
'''have a special APL2 defined utility for that purpose. Let us call'' °
' '''a utility function to prompt for numeric values GETNO'',r' °
'show ''ÉFX ''''U╜GETNO W'''' ''''Σ Prompt for numeric data'''' ''''W °
╪ U╜É''''''' '1 showfn ''GETNO''' °
'''Function GETNO prints the prompt first, and then applies the quad'' °
,r' °
'show ''N╜GETNO ''''Enter your age in years'''''' ''T╜''''You are'''', °
N,''''years old''''''' 'show ''DISPLAY T''' °
'''Since we desire to make function GETNO a useful utility, let us con °
sider''' °
'''what additional features it should have. Let us agree that GETNO sh °
ould''' °
'''prompt for a numeric scalar or vector entry. Beyond that we may wis °
h to''' '''specify the following:'',r' °
''' a. If a vector, the number of elements in the vector''' °
''' b. Whether the values are to be integers. If fractions, then spec °
ify''' ''' the number of decimal digits.''' °
''' c. The largest allowed values''' °
''' d. The smallest allowed values''' °
''' e. What to do if some entries are outside permitted range'',r' °
'''To support options (a to d) we should add a left argument to GETNO' °
',r' °
'FN╜''U╜V GETNO W;E'' ''Σ Prompt for numeric data'' ''W ╪ U╜É ╪ ╕(0=ÉN °
C ''''V'''')/0''' 'show ''πFN''' °
'''If the left argument is absent (i.e. GETNO is used monadically) the °
n''' '''no further processing will be done'',r' °
'show ''FN╜FN,Γ''''L0:╕((╞V)≤µ,U)/L1 ╪ U╜U,É ╪ ╕L0''''''' °
'''If the number of entries is less than the specified value in the fi °
rst''' °
'''element of the left argument, then request additional values''' °
'do' °
'show ''FN╜FN,Γ''''L1:U╜(╞V)╞U ╪ ╕(1=µ,V)/0 ╪ U╜(╛.5+U⌡10*V[2])÷10*V[2 °
]''''''' °
'''Save only as many values as specified in the left argument. Then, i °
f the''' °
'''left argument has only one element, exit. Else do a half-adjust in °
the''' '''last decimal position.''' 'do' °
'show ''FN╜FN,Γ''''╕(2=µV)/0 ╪ V╜(4⌐µV)╞V''''''' °
'''If the left argument has only two elements, exit. Else make sure th °
at''' °
'''the left argument has at least four elements (This provides a defau °
lt''' '''of zero for the smallest permissible value.)'',r' °
'show ''FN╜FN,Γ''''E╜(U>V[3])-U<V[4] ╪ ╕(^/E=0)/0''''''' °
'''If the values of the vector are all within range, exit. Else contin °
ue'',r' °
'show ''FN╜FN,Γ''''V╜6╞V,V[3 4] ╪ U[(E=1)/∞µE]╜V[5] ╪ U[(E=²1)/∞µE]╜V[ °
6]''''''' °
'''If the left argument has only four elements, use the values of V[3 °
4]''' °
'''as replacement defaults. Replace values outside range by upper and' °
'' '''lower bounds.'',r' 'show ''ÉFX FN''' '1 showfn ''GETNO''' °
'show ''5 GETNO ''''Enter numbers two at a time''''''' °
'''The function requested new values until you entered 6. Then it save °
d only 5'',r' 'show ''2 4 GETNO ''''Enter: *2 3 4''''''' °
'''The function returned results to 4 decimal points'',r' °
'show ''10 0 20 10 ²2 ²1 GETNO ''''Enter: 3⌡∞10''''''' °
'''If you entered the requested expression, function GETNO returns a'' °
' °
'''vector of length 10 with negative values in positions where the''' °
'''expression generates values outside the desired range (10 to 20).'' °
X' 'endd' °
*(1997 6 23 12 50 19 508) °
FTEACH3 ÉFX 'TEACH3;N;C;FN' 'Σ Format, Execute and the DOIF utility' °
''' THE EXECUTE AND FORMAT FUNCTIONS'',r' °
'''The EXECUTE primitive (») provides the means of converting valid AP °
L2''' '''character string expressions into evaluated results.'',r' °
'show ''C╜''''1.56 2 34'''''' ''µC'' ''DISPLAY C'' ''N╜»C'' ''µN'' ''D °
ISPLAY 2⌡N''' °
'''In the example we converted the character string C representing a'' °
' °
'''numeric vector to the numeric vector N. In commercial applications' °
'' °
'''this is very useful, since numeric data is commonly stored in files °
''' °
'''as character strings. To store numeric arrays in files we also need °
''' °
'''the converse function. In APL2 this process is done with the FORMAT °
''' °
'''primitive function. The monadic version of format is given by the s °
ymbol''' °
'''«, also called the thorn. (We will study the dyadic version of form °
at''' '''in a later session.)'',r' 'show ''µÉ╜«N'' ''DISPLAY «N''' °
'''These two functions are dual for vectors only if we begin with the' °
'' '''format of a numeric vector. Here is why'',r' °
'show ''µC╜''''1 2 3'''''' ''µ«»C''' °
'''The starting character string need not comply with the strict rules °
''' °
'''for conversion of a numeric vector to a string using the « function °
.''' 'do' °
'''For that matter, the character expression need not even be a symbol °
''' '''representation of a numeric vector. It can be ANY valid APL2''' °
'''expression'',r' °
'show ''C╜''''+/5 4µ6+∞15'''''' ''N╜»C'' ''DISPLAY N''' °
'''Some APL2 theoreticians are uneasy with the execute command, becaus °
e''' °
'''it tends to be misused. In some studies of user defined functions i °
t''' °
'''was found that the execute can frequently be avoided by a more care °
fully''' '''thought out algorithm.'',r' °
'''There are times, however, when the execute can be a very powerful t °
ool.''' °
'''Here is an example of a utility function that uses the execute. (No °
te''' °
'''that in this workspace, utility functions have been defined in lowe °
r''' '''case.)'',r' '1 showfn ''doif''' °
'''NOTE: Actually this function has become obsolescent with the''' °
''' introduction of the DIAMOND (╪) separator. (We will study''' °
''' the System function ÉEA in later sessions, but for the time'' °
' °
''' being, the left argument of ÉEA is evaluated only if the righ °
t''' ''' argument fails.)''' 'do' °
'''Function ''''doif'''' is dyadic. It tests the left argument which m °
ust''' °
'''return a boolean scalar or vector. If the result of the test is 1'' °
' °
'''then the right argument is executed. The function returns the boole °
an''' '''result'',r' 'show ''N╜2'' ''C╜(N<10) doif ''''∞N'''''' ''C''' °
'''The right argument must be valid APL2 expression as a character str °
ing.''' '''It may even be a vector of APL2 expressions'',r' °
'show ''N╜2 12 3'' ''C╜(N<10) doif ''''∞2'''' ''''∞3'''' ''''∞4'''''' °
X''C''' 'endd' °
*(1997 6 24 11 41 32 524) °
FTEACH4 ÉFX 'TEACH4;RL' 'Σ Random link and Time stamp' 'RL╜?100' °
''' RANDOM LINK AND TIME STAMP'',r' °
'''We have previously studied the functions ROLL and DEAL, but we have °
''' °
'''not discussed how these functions generate random values. Ignoring °
the''' °
'''actual algorithm, there is a SYSTEM variable called RANDOM LINK tha °
t''' '''determines the actual sequence of random numbers.'',r' °
'''Random link is stored in ÉRL. It will accept integer values and wil °
l''' °
'''return its current value which changes each time the roll or deal'' °
' '''function is invoked'',r' °
'show ''RL╜É╜ÉRL'' ''?5µ100'' ''ÉRL'' ''ÉRL╜RL'' ''?3µ100'' ''?2µ100'' °
''ÉRL''' °
'''One consequence of this is that the "random results" in a workspac °
e''' °
'''may ALWAYS return the same sequence, each time that workspace is lo °
aded.''' °
'''This is because the value of ÉRL is stored with the workspace.''' °
'do' °
'''In some applications this may not be desired. How can the random li °
nk''' °
'''be INITIALIZED when the workspace is loaded? One way of doing it is °
to''' °
'''use another SYSTEM function called the TIME STAMP. The time stamp'' °
' °
'''(ÉTS) generates a numeric vector of length 7. The values represent °
the''' °
'''YEAR, MONTH, DAY, HOUR(24), MINUTE, SECOND, and MILISECOND of the i °
nstant''' '''the time stamp was invoked'',r' 'show ''ÉTS'' ''ÉTS''' °
'''Since the time when a workspace is loaded is unpredictable, it is a °
''' °
'''convenient way of extracting a random link. To do that, simply ente °
r''' °
'''an expression such as the following in the appropriate function'',r °
X' 'show ''RL╜ÉRL╜+/²3╞ÉTS''' 'endd' °
*(1997 6 24 12 41 26 504) °
FTEACH5 ÉFX 'TEACH5;DECK;T;FN' 'Σ The game of BLACKJACK' °
'''We will now illustrate the usage of random link and the time stamp' °
'' '''by developing an application of the game of blackjack.''' 'do' °
''' SHUFFLING, DISPLAYING AND DEALING CARDS'',r' °
'''As in any card game, cards have to be shuffled and then dealt to th °
e''' °
'''players. We must, therefore, begin by defining a card deck, definin °
g''' °
'''the process of shuffling cards, and the process of dealing cards.'' °
,r' °
'''NOTE: You may wish to use the font... option in the options pull do °
wn''' °
''' menu to increase the size of your font (12 or 14 should do it °
).''' 'do' °
'''Since a card deck contains 52 cards, it makes sense to associate''' °
'''each card with an integer in the interval (1,52). We will use the'' °
' °
'''following scheme: For integers 1-13 we will associate CLUBS, for''' °
'''14-26 DIAMONDS, for 27-39 HEARTS, and for 40-52 SPADES. Within each °
''' °
'''suit, the sequence will be 2,3,4,5,6,7,8,9,10,J,Q,K,A. In this way' °
'' °
'''the integer 10, for example will represent the JACK of CLUBS, and'' °
' '''the integer 28 will represent the 3 of HEARTS.''' 'do' °
'''We define a variable called DECK to contain all cards in a deck'',r °
' 'show ''DECK╜∞52''' '''We next shuffle this deck'',r' °
'show ''ÉRL╜+/²3╞ÉTS'' ''DECK╜DECK[52?52]'' ''4 13µDECK''' °
'''We have shuffled the deck of cards, but it is difficult to see what °
''' °
'''these integers stand for. What we need is a display function'',r' °
'FN╜''U╜SHOW C'' ''Σ Display cards C''' °
'FN╜FN,Γ''U╜(3Φ''''JQKA23456789'''',Γ''''10'''')[1+13|C]''' °
'FN╜FN,Γ''U╜U,■(ÉAV[6 5 4 7])[⌐C÷13]'' ╪ πFN ╪ T╜ÉFX FN' 'do' °
'''We can now display cards from this deck'',r' °
'show ''2╞DECK'' ''SHOW 2╞DECK''' °
'''Next we need a function to deal cards from this deck'',r' °
'FN╜''U╜DEAL W'' ''Σ Deal W cards'' ''U╜W╞DECK'' ''DECK╜W╟DECK'' ╪ πFN °
╪ T╜ÉFX FN' 'r' 'show ''SHOW 4 5µDEAL 20'' ''µDECK''' °
'r,''(Function DEAL does not handle the case when the deck contains fe °
wer''' °
'''cards than requested. This would be needed in the game of poker.)'' °
,r' 'do' ''' THE GAME OF BLACKJACK'',r' °
'''Let us now look at the basic rules of BLACKJACK. For simplicity, we °
''' °
'''will assume there are only two players: Dealer and Player. We will' °
'' '''also ignore betting in this sample game.'',r' °
''' A. Dealer shuffles the deck, and deals two cards each. (We will sh °
ow''' °
''' all cards as dealt, and deal to Player first which is not the w °
ay''' ''' the actual game is played.)'',r' °
''' B. The value of cards is that of their pip (number on the card)''' °
''' Face cards count 10, and the Ace can be counted as 1 OR 11'',r' °
''' DECISION RULES'',r' °
''' 1. If player sees a 10 value card and an ACE, player says''' °
''' BLACKJACK and wins.''' °
''' 2. If cards ad up to 15 or more, but less than 22, player says' °
'' °
''' I hold. Action then passes to the next player (Dealer).''' °
''' 3. If cards in players hand add up to 22 or more player LOSES.' °
'' °
''' 4. Else player says HIT ME, gets another card, and goes to rule °
2'',r' °
''' C. After Player stops, Dealer''''s cards are evaluated under the'' °
' ''' same rules. EXCEPTION: in case of draw, Dealer wins.''' 'do' °
''' TWO MORE UTILITIES'',r' °
'''Before we define function BLACKJACK, we need two more defined objec °
ts.''' °
'''We need a function to evaluate a blackjack hand, and we need an''' °
'''operator that can be used to determine what to do with a given hand °
.'',r' '''Let us call the function to evaluate a hand EVAL'',r' °
'FN╜''U╜ EVAL W;R'' ''Σ Evaluate a blackjack hand''' °
'FN╜FN,Γ''U╜+/((∞10),3µ10)[1+R╜13|W]''' °
'FN╜FN,Γ''╕(~0εR)/0 ╪ U╜0¥U,(22>U+10)/U+10'' ╪ πFN ╪ T╜ÉFX FN' °
'r,''The last expression in EVAL takes care of a hand containing aces' °
',r' 'show ''SHOW 13 26 39'' ''EVAL 13 26 39''' °
'''Finally, we define the operator ISIN. This operator returns a boole °
an''' '''scalar in response to a range inquiry'',r' °
'FN╜''U╜V (f ISIN) W'' ''Σ Do cards W add up to range V''' °
'FN╜FN,''U╜(0¥ΦV) f W'' ''╕(1=µ,V)/0'' ''U╜U^W f V[2]'' ╪ πFN ╪ T╜ÉFX °
FN' °
'r,''Notice that in the last line the W preceeds V[2] in the compariso °
n.''' '''Let us see how ISIN works'',r' °
'show ''21 =ISIN 21'' ''14 21 <ISIN É╜13+∞9'' ''15 >ISIN É╜12+∞4''' °
X 'endd' °
*(1997 6 27 13 43 42 592) °
FTEACH6 ÉFX 'TEACH6;T;FN' °
'Σ Using utility ''doif'' in function BLACKJACK' °
''' A PROGRAMMING STYLE EDITORIAL'',r' °
'''In what follows, we will illustrate a programming style. Since this °
''' °
'''subject does not describe new APL2 primitives or its architecture,' °
'' '''this section is labelled as an editorial.''' 'do' °
'''The object of this exercise is to display one possible programming' °
'' °
'''style that one might use in solving a particular problem. We could' °
'' °
'''define function BLACKJACK "conventionally" by writing code that''' °
'''makes no distinction between the game, the logic and the rules of'' °
' °
'''the game. Indeed as an exercise, you should try to define such a''' °
'''function at the end of this lesson. (Such conventional version of'' °
' '''blackjack, written by Harry Bertucelli is available.)''' 'do' °
''' A SAMPLE EXPERT SYSTEM'',r' °
'''An early version of an Expert System, was first introduced by''' °
'''Post in 1943. It is called a PRODUCTION SYSTEM. We will design the' °
'' °
'''card game of BLACKJACK using this Production System approach.'',r' °
'do' °
'''We begin by defining function INFEN (for INFerence ENgine). This''' °
'''function will will combine the rules of the game AND its logic'',r' °
'show ''FN╜''''U╜INFEN W;P;T'''' ''''Σ Blackjack rules and logic'''' ' °
'''U╜0''''''' °
'''Initialization includes setting U to zero --to indicate continuatio °
n''' °
'''of the game. The right argument to INFEN is a nested string of word °
s''' °
'''that apply to a specific player. For the player, these would be:''' °
'''(Player, I win, I fold, Hit me, I stand, BLACKJACK).''' 'do' °
'show ''FN╜FN,Γ'''' W[1],''''''''gets'''''''' 2 ''''''''cards:'''''''' °
╪ SHOW P╜DEAL 2''''''' °
'''The game is initialized. Two cards are dealt and displayed.''' °
'do' °
'show ''FN╜FN,Γ''''L0:╕(21⌠ISIN R╜EVAL P)/L1 ╪ W[6 2] ╪ U╜1 ╪ ╕0'''''' °
' °
'''If the cards add up to 21, the game is over. The value of U is set °
to''' °
'''one to indicate that fact. Else if R<21, more tests have to be made °
.''' °
'''Variable R which contains the value of the hand is GLOBAL to functi °
on''' '''INFEN. (This is called a "side effect".)''' 'do' °
'show ''FN╜FN,Γ''''L1:╕(21>ISIN R)/L2 ╪ U╜1 ╪ W[3] ╪ ╕0''''''' °
'''If R is greater than 21, player loses. The value of U is also set t °
o''' '''one to indicate the end of the game.''' 'do' °
'show ''FN╜FN,Γ''''L2:╕(~14 21<ISIN R)/L3 ╪ ΓW[5] ╪ ╕0''''''' °
'''If the value is greater than 14 but less than 21, Player says "I st °
and"''' 'do' °
'show ''FN╜FN,Γ''''L3:W[4] ╪ T╜æ ╪ SHOW P╜P,DEAL 1 ╪ ╕L0''''''' °
'''If the value is less than 15, player says "hit me", and pauses. The °
n a''' °
'''new card is shown to the player and evaluation is repeated.''' °
'T╜ÉFX FN' 'do' '''Here is a listing of this function''' °
'1 showfn ''INFEN''' 'do' °
'''Before we can try out this function, we must define DECK'',r' °
'show ''DECK╜52?52''' °
'show ''INFEN ''''Player'''' ''''I win'''' ''''fold'''' ''''Hit me'''' °
''''I stand'''' ''''BJ''''''' °
'''Function INFEN works. Now we can define the niladic function BLACKJ °
ACK.''' °
'''In my teminology a niladic function is called a COMMAND. It serves °
as''' '''an entry to an application.'',r' °
'FN╜''BLACKJACK ;D;DECK;T;S;R'' ''Σ Command for game of Blackjack''' °
'FN╜FN,Γ''DECK╜∞52 ╪ DECK╜DECK[52?52]''' °
'FN╜FN,Γ''D╜''''Player'''' ''''I win'''' ''''I fold'''' ''''Hit me'''' °
''''I stand'''' ''''BLACKJACK''''''' °
'FN╜FN,Γ''╕(INFEN D)/0 ╪ T╜æ ╪ ╕(21<S╜R)/0''' °
'FN╜FN,Γ''D╜(5╞''''Dealer'''' ''''You lose'''' ''''You win''''),5╟D ╪ °
╕(INFEN D)/0''' 'FN╜FN,''╕(S≥R)/L0 ╪ D[2] ╪ ╕0'' ''L0:D[3]'' ╪ ÉFX FN' °
'1 showfn ''BLACKJACK''' °
'''Function BLACKJACK first defines a card deck and shuffles it. Then °
a''' °
'''dictionary of terms used by the player is stored in local variable °
D.''' °
'''If Player does not end the game (by getting a BLACKJACK or by losin °
g),''' °
'''then the game continues. The player''''s score is saved in S (recal °
l that''' °
'''R is a "side effect" of function INFEN). A pause is produced by ass °
igning''' °
'''a quote quad to T. The dictionary is updated to that of the dealer, °
and''' '''function INFEN is invoked for the dealer.'',r' 'do' °
'''Here is a sample run of function BLACKJACK'',r' °
X 'show ''BLACKJACK''' 'endd' °
*(1997 6 30 20 48 20 564) °
FTEACH7 ÉFX 'TEACH7;F;FN;T' 'Σ Another version of BLACKJACK' °
''' A RULE BASED APPROACH'',r' °
'''Function BLACKJACK works fine, but the decision making is hardwired °
''' °
'''in function INFEN. There is yet another way to solve this game. The °
''' °
'''idea is to write a UTILITY function called INFEN2, and to store the °
''' '''rules of the game in nested arrays.''' 'do' °
'FN╜''INFEN2 W;N;ANTE ;CONS'' ''Σ A simple Inference Engine'' ''(ANTE °
CONS)╜W ╪ N╜0''' °
'T╜ÉFX FN,Γ''L0:╕(²1=N)/0 ╪ N╜N+1 ╪ ╕(~U╜0¥»NπANTE)/L0 ╪ »NπCONS ╪ ╕L0 °
''' '''We now illustrate this approach''' '1 showfn ''INFEN2''' °
'''The right argument W is a nested array. Its two components are the' °
'' °
'''antecedents and the consequents of a set of rules. The two local''' °
'''variables ANTE and CONS are initialized, as well as the rule counte °
r N.'',r' °
'''The first rule to be looked at is rule 1. The function evaluates th °
e''' °
'''first element of the nested string ANTE (for Antecedent). If this r °
eturns''' °
'''a 1 (TRUE), then the first element of nested string CONS (for Conse °
quent)''' °
'''will be evaluated next. Note that if NπCONS contains an expression °
of''' '''the form''' ''' N╜²1 or (...,N)╜...,²1''' °
'''then on branchimg back to L0, there will be an exit from INFEN2. Th °
e''' °
'''number of rules evaluated by INFEN2, will depend entirely on the''' °
'''contents of arrays ANTE and CONS. The elements of ANTE must return °
a''' °
'''boolean value, but the elements of CONS may produce arbitrary side' °
'' '''effects.'',r' °
'''Note that function INFEN2 is perfectly general. It could be used fo °
r''' °
'''any other "rule based" application. Indeed, The consequents of a ru °
le''' °
'''set may invoke INFEN2 recursively using additional rule sets.''' °
'do' '''Let us now see how we must re-design function BLACKJACK.''' °
'FN╜''BLACKJACK2 ;D;DECK;T;S;R'' ''Σ Command for game of Blackjack''' °
'FN╜FN,Γ''DECK╜∞52 ╪ DECK╜DECK[52?52] ╪ P╜DEAL 2''' °
'FN╜FN,Γ''D╜''''Player'''' ''''I win'''' ''''I fold'''' ''''Hit me'''' °
''''I stand'''' ''''BLACKJACK''''''' °
'FN╜FN,Γ''INFEN2 RULES ╪ T╜æ ╪ ╕(21<S╜R)/0''' °
'FN╜FN,Γ''D╜(5╞''''Dealer'''' ''''You lose'''' ''''You win''''),5╟D ╪ °
INFEN2 RULES''' °
'FN╜FN,''╕(S≥R)/L0 ╪ D[2] ╪ ╕0'' ''L0:D[3]'' ╪ T╜ÉFX FN' °
'1 showfn ''BLACKJACK2''' °
'''This function is essentially the same as BLACKJACK. The only differ °
ence''' °
'''is in function INFEN2. Its right argument now is the array of rules °
.''' 'do' '''Here are the simple rules of blackjack'',r' °
'''RULE ANTECEDENT CONSEQUENT'',r' °
''' 1 1 D[1] ╪ ''''gets'''' 2 ''''cards:'''' ╪ SHOW P╜D °
EAL 2 ╪ T╜æ''' ''' 2 21=ISIN R╜EVAL P D[6 2] ╪ N╜²1''' °
''' 3 21<ISIN R╜EVAL P D[3] ╪ N╜²1''' °
''' 4 14 22<ISIN R D[5] ╪ N╜²1''' °
''' 5 1 D[4] ╪ SHOW P╜P,DEAL 1 ╪ N╜1 ╪ T╜æ'',r' 'do' °
'ANTE╜''1'' ''21=ISIN R╜EVAL P'' ''21<ISIN R╜EVAL P'' ''14 22<ISIN R'' °
''1''' °
'CONS╜Γ''D[1] ''''gets'''' 2 ''''cards:'''' ╪ SHOW P╜DEAL 2 ╪ T╜æ''' °
'CONS╜CONS,''D[6 2] ╪ N╜²1'' ''D[3] ╪ N╜²1'' ''D[5] ╪ N╜²1''' °
'CONS╜CONS,Γ''D[4] ╪ SHOW P╜P,DEAL 1 ╪ T╜æ ╪ N╜2''' 'RULES╜ANTE CONS' °
X 'show ''DISPLAY π1πRULES'' ''DISPLAY π2πRULES'' ''BLACKJACK''' '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 17 11 35 51 556) °
Ferase ÉFX °
'erase;t;EXIT;GO;HELP;DISPLAY;BIND;REVIEW;RULE;SHOW;DEAL;EVAL;ISIN;INF °
EN;BLACKJACK;DISCLAIMER' 'Σ Erase all global functions and variables' °
't╜ÉNL 3' 't╜(~t^.εlc,'' '')≡t' 't╜ÉEX(~t[;∞5]^.=''TEACH'')≡t' °
X 't╜ÉNL 2' '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 7 37 344) °
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' °