Program 59 makes use of the readkey predicate from Program 58. If Program 58 has been saved in a disk file called PROG58.PRO, the definition of readkey can be easily incorporated into Program 59 using the include compiler directive (see Chapter II). It takes the form include "filename" and causes the contents of the named text file to be inserted into the containing program at the position of the include directive. Thus, using include IPROG58.PRO" after compilation, Program 59 will contain the complete text of Program 58. However, since we wish to give a different goal. to initiate the field editor from that used to demonstrate readkey, it is necessary to save Program 58 on disk without the goal it contains. II Program 59 II include I prog58.pro" I'excluding the goal'l domains row,col,length=integer field=f(row,col,length) position=pos(row,col) predicates scr(field,position,key) goal Row=lO,Col=lO,Length=30,cursor(Row,Col), makewindow(1,23,1,"Example Editor",O,O,25,80), write("Edit the text. Use the arrow keys to move"), field_attr(Row,Col,Length,112), scr(f(Row,Col,Length),pos(Row,Col),home),nl,nl, field_str(Row,Col,Length,Contents), write("Edited contents: ",Contents). clauses scr(_,_,esc):-l, fail. scr(_,_,fkey(lO)):-l. scr(f(Row,Col,L),pos(R,C),char(Ch)):scr_char(R,C,Ch),Cl=C+l,Cl
If a key has been pressed since the last read operation was performed, inkey succeeds by binding the variable CharParam to the ASCII character associated with the key pressed. inkey fails if no key has been pressed. Thus inkey-unlike readchar-allows execution to continue even if a key has not been pressed. The example below uses inkey and time to test a person's reaction time. 126 II Program bD II predicates wait(char) equal(char,char) test(string) goal makewindow(3,7,D,IIII,D,D,2S,8D), makewindow(2,7,7,IIKey to press now ll ,2,S,b,7D), makewindow(:L,7,7,IIAccepted lettersll ,8,:LD,:LD,bD), Word = IIPeter Piper picked a peck of pickled peppersll), write("Please type :\n\tll,Word,\n\t), time(O,O,O,D),test(Word), timeL, _, 5, H), write(lI\nYou took 11,5,11 seconds and II,H,II hundredthsll). clauses wait(X):- inkey(Y),equal(X,Y). wait(X):- shiftwindow(2),write(X),wait(X). test(W):- frontchar(W,Ch,R),wait(Ch), shiftwindow(2),write(Ch),test(R). test(lIlI) . equal(X,X) :-!. equal(_,_):-beep,fail. <strong>Turbo</strong> <strong>Prolog</strong> Owner's Handbook
- Page 2:
Turbo Prolog Owner's Handbook Copyr
- Page 5 and 6:
Chapter 4 Tutorial II: A Closer Loo
- Page 7 and 8:
Dynamic Databases in Turbo Prolog D
- Page 9 and 10:
fail field_attr field_str filepos f
- Page 11 and 12:
I 1-2 Sample Diagnostic Display ...
- Page 13 and 14:
The tutorials cover all aspects of
- Page 15 and 16:
Prolog is a full-fledged compiler w
- Page 17 and 18:
Turbo Prolog has a built-in pattern
- Page 19:
In addition to the version of Turbo
- Page 27 and 28:
Saving a Window Layout Select Save
- Page 29 and 30:
The clauses section contains a coll
- Page 31:
Objects and Relations In Turbo Prol
- Page 35:
Since Person I and Person2 are both
- Page 39 and 40:
mother(marilyn,beverly). mother(ala
- Page 41 and 42:
so that a goal of the form similar_
- Page 43 and 44:
32 Turbo Prolog Owner's Handbook
- Page 45:
1* Program b *1 domains person, hob
- Page 48:
Program 7 is a complete Turbo Prolo
- Page 57:
To declare a domain for lists of in
- Page 62:
5 Tutorial III: Turbo Prolog's Rele
- Page 66 and 67:
The clause Turbo Prolog chooses to
- Page 68 and 69:
Use of Fail Turbo Prolog contains a
- Page 72 and 73:
Exercise Suppose an average taxpaye
- Page 74 and 75:
6 Tutorial IV: Arithmetic, Simple I
- Page 78 and 79:
eply(_,_,D) :- D < 0, write("No sol
- Page 80:
and A= -0.756802 tes t2 ( L; , B) .
- Page 85: DEBUGGING AND TRACING Before a prog
- Page 88 and 89: 7 Tutorial V: Seeing Through Turbo
- Page 90 and 91: makewindow( ... ) shiftwindow( ...
- Page 92 and 93: You can change the attribute of the
- Page 97: A WORD GUESSING GAME USING WINDOWS
- Page 100 and 101: goal 1* Program 32 *1 makewindow(1,
- Page 102: 8 Tutorial VI: Graphics and Sound A
- Page 106: 1 Program 37 1/ predicates inspiral
- Page 109 and 110: 98 Turbo Prolog Owner's Handbook
- Page 111: To access a file, it must first be
- Page 119 and 120: Program 50 uses random to select th
- Page 121 and 122: 110 1* Program 51*1 predicates anim
- Page 123 and 124: The other rule for positive will as
- Page 125 and 126: Try the program with the goal route
- Page 127 and 128: track as soon as one solution has b
- Page 129 and 130: * Program 55 */ domains loc = right
- Page 132: string word ("" , [ 1 ) : -! . stri
- Page 138 and 139: 11 Programmer's Guide This chapter
- Page 140 and 141: Reserved Names The following are re
- Page 142 and 143: 2. mylist = elementDom* This is a c
- Page 144: symbol (\) followed by an ASCII cod
- Page 150 and 151: For example, given trace domains li
- Page 152 and 153: save("mydata.dba") the file mydata.
- Page 154 and 155: domains file name, address age sex
- Page 157: Tail recursion elimination is a tec
- Page 160 and 161: Determinism, Non-determinism and Ho
- Page 163 and 164: • The DOS linker, LlNK.EXE, must
- Page 165 and 166: Compiling and Linking the Modules B
- Page 170 and 171: so that the data segment addressed
- Page 172: clauses dosver(VERSION): AX=L;8*2
- Page 177: The Options Menu The Options pull-d
- Page 183: Save Configuration S saves the curr
- Page 190:
ARITHMETIC FUNCTIONS AND PREDICATES
- Page 193 and 194:
• list of the possible flow patte
- Page 195 and 196:
date(Year, Month, Day ) (integer,in
- Page 197:
contained inside that window, the v
- Page 200 and 201:
less than or greater than zero, a b
- Page 202 and 203:
eadchar( CharVariable) (char) : (0)
- Page 204 and 205:
storage(StackSize,HeapSize, TrailSi
- Page 207 and 208:
f - Reals in fixed decimal notation
- Page 209 and 210:
Predicate and Database Section
- Page 211 and 212:
SYSTEM liMITS «arithmet
- Page 213:
ASCII Character Set (continued) Spe
- Page 216 and 217:
B Error Messages Following is a com
- Page 218 and 219:
600 Too many domain names 601 Too m
- Page 220 and 221:
C PLINK USE OF THE FILE PLINK.BAT P
- Page 222 and 223:
D PROWG.SYS The table below describ
- Page 224 and 225:
E Using Turbo Prolog with Turbo Pas
- Page 226 and 227:
F Glossary anonymous variable The v
- Page 228 and 229:
list A special sort of object consi
- Page 230 and 231:
Index A Anonymous Variable, 22-23 A
- Page 232:
p Pascal procedures. calling from T
- Page 237 and 238:
SlnBiCI The Organizer For The Compu
- Page 242 and 243:
Learn Pascal From The Folks Who Cre
- Page 245:
2VRBO PASCAt EDJ2OR7tDr.BOX It's Al
- Page 249 and 250:
NOTES
- Page 251 and 252:
NOTES
- Page 253 and 254:
NOTES
- Page 255 and 256:
NOTES
- Page 257:
NOTES