03.06.2013 Views

Turbo Prolog

Turbo Prolog

Turbo Prolog

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

If a key has been pressed since the last read operation was performed, inkey succeeds<br />

by binding the variable CharParam to the ASCII character associated with the key<br />

pressed. inkey fails if no key has been pressed. Thus inkey-unlike readchar-allows<br />

execution to continue even if a key has not been pressed. The example below uses<br />

inkey and time to test a person's reaction time.<br />

126<br />

II Program bD II<br />

predicates<br />

wait(char)<br />

equal(char,char)<br />

test(string)<br />

goal<br />

makewindow(3,7,D,IIII,D,D,2S,8D),<br />

makewindow(2,7,7,IIKey to press now ll ,2,S,b,7D),<br />

makewindow(:L,7,7,IIAccepted lettersll ,8,:LD,:LD,bD),<br />

Word = IIPeter Piper picked a peck of pickled peppersll),<br />

write("Please type :\n\tll,Word,\n\t),<br />

time(O,O,O,D),test(Word),<br />

timeL, _, 5, H),<br />

write(lI\nYou took 11,5,11 seconds and II,H,II hundredthsll).<br />

clauses<br />

wait(X):- inkey(Y),equal(X,Y).<br />

wait(X):- shiftwindow(2),write(X),wait(X).<br />

test(W):- frontchar(W,Ch,R),wait(Ch),<br />

shiftwindow(2),write(Ch),test(R).<br />

test(lIlI) .<br />

equal(X,X) :-!.<br />

equal(_,_):-beep,fail.<br />

<strong>Turbo</strong> <strong>Prolog</strong> Owner's Handbook

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!