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.

goal<br />

1* Program 30 *1<br />

makewindow(l,7,7,"Directory for disk AII,o,o,20,3S),<br />

system("dir a:"),<br />

makewindow(2,7,7,"Directory for disk B",o,L;o,2o,3S),<br />

system("dir b:"),<br />

makewindow(3,7,7,"I,21,2S,3,30).<br />

Program 31 illustrates a file copy utility with a very elegant, window-driven user interface.<br />

In this design, the user needn't remember whether it is the name of the copy or<br />

the name of the file to be copied that comes first in the DOS copy command (a point of<br />

confusion for many novice computer users). Program 31 uses the standard predicate<br />

concat (see Chapter 9) which takes the form<br />

concat(X,y,Z)<br />

and is true if Z is bound to the concatenated strings to which X and Yare bound. Thus<br />

concat("hello"," mother",X)<br />

will succeed and binds X to "hello mother" and<br />

concat("valerie","ann","valerie-ann")<br />

fails (because of the extra hyphen in "valerie-ann").<br />

goal<br />

Date and Time<br />

1* Program 31 *1<br />

makewindow(l,7,7,ISource",o,o,2o,3S),<br />

write("Which file do you want to copy ?"),<br />

cursor(3,B),readln(X),<br />

makewindow(2,7,7,IDestination",o,L;o,2o,3S),<br />

write("What is the name of the new copy ?"),<br />

cursor(3,B),readln(Y),<br />

concat(X," ",Xl) ,concat(Xl, Y, Z),<br />

concat("copy ",Z,W),<br />

makewindow(3,7,7,IProcess",M,lS,B,So),<br />

write(" Copying ",X," to ",Y),cursor(2,3),<br />

system(W) .<br />

There are two other DOS-related standard predicates that are handy to use: date and<br />

time. They can each be used in two ways, depending on whether all their parameters<br />

are free or bound on entry. If all variables in<br />

time(Hours,Minutes,Seconds,Hundredths)<br />

are bound, time will reset the internal system time clock. If all variables are free, they<br />

will be bound to the current values of the internal clock.<br />

Date, which also relies on the internal system clock, operates in the same way, and<br />

takes the form<br />

date(Year,Month,Day)<br />

Program 32 uses time to display the time elapsed during a listing of the directory in<br />

drive A.<br />

88 <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!