home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / ANSWERS.ARC / ANS_257.PRO < prev    next >
Encoding:
Prolog Source  |  1988-06-21  |  1.9 KB  |  75 lines

  1. /*
  2.    Turbo Prolog 2.0, Answer to Exercise on page 257.
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5. */
  6.  
  7. Domains
  8.   name, address, city ,
  9.   company, mail_stop  = string
  10.   state, zip          = symbol
  11.  
  12. Database
  13.   address ( name, company, mail_stop, address, city, state, zip )
  14.  
  15. Predicates
  16.   print_em ( char )
  17.   print_labels
  18.   print_company ( string )
  19.   print_stop ( string )
  20.   nondeterm repeat
  21.   
  22. Clauses
  23.   print_em('s') :- 
  24.       !, clearwindow ,
  25.       print_labels.
  26.   print_em('p') :-
  27.       !, write("\n\n  Printing...") ,
  28.       writedevice(printer) ,
  29.       print_labels ,
  30.       flush(printer), nl ,
  31.       writedevice(screen), nl, nl.
  32.   print_em(_) :-
  33.       beep ,
  34.       write("\n\n  Not a valid resopnse...press a key to continue: ") ,
  35.       readchar(_), clearwindow ,
  36.       fail.
  37.  
  38.   print_labels :-
  39.       address(Name, Co, Stop, Add, City, State, Zip) ,
  40.         print_company(Co) ,
  41.         write(Name), nl ,
  42.         print_stop(Stop) ,
  43.         write(Add), nl ,
  44.         writef("%, %  %", City, State, Zip) ,
  45.         nl, nl, nl ,        % adjust new lines to fit your lables
  46.       fail ; true.
  47.       
  48.   print_company("") :- !.    % if company is blank, do nothing
  49.   print_company(Co) :-
  50.       write(Co), nl.
  51.       
  52.   print_stop("") :- !.      % if stop is blank, do nothing
  53.   print_stop(Stop) :-
  54.       write(Stop), nl.
  55.       
  56.   repeat :- true ; repeat.
  57.       
  58.   address("Alice Brown", "", "", "23 N. Western Ave.", 
  59.           "Calamazo", "TN", "32917-7098").
  60.   address("Charles B. Knorthrop", "Maxin Corp.", "", "2000 Main St." ,
  61.           "San Francisco", "CA", "94928").
  62.   address("Maxine Wilson", "Bendix Ltd.", "Mail Stop 269" ,
  63.           "3100 E Madison Ave.", "New York", "NY", "10001").
  64.           
  65. GOAL
  66.   makewindow(1,2,3," Print Labels ", 0,0,25,80) ,
  67.   repeat ,
  68.     cursor(2,2) ,
  69.     write("Do you want to print to the screen or the printer (S/P): ") ,
  70.     readchar(Where) ,
  71.     upper_lower(Where, There) ,
  72.     print_em(There) ,
  73.     write("  Done.") ,
  74.     readchar(_).
  75.