home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / ANSWERS / ANS_159A.PRO < prev    next >
Encoding:
Prolog Source  |  1990-03-26  |  1019 b   |  33 lines

  1. /*
  2.    PDC Prolog, Answer to first Exercise on page 159.
  3.    
  4.    Copyright (c) 1986, 90 by Prolog Development Center
  5. */
  6.    
  7. /* 
  8.  *   Uses repeat to keep accepting characters, printing 
  9.  *   them all in upper case until the user presses Enter. 
  10.  */
  11.  
  12. Predicates
  13.    nondeterm repeat
  14.    typewriter
  15.  
  16. Clauses
  17.    repeat.
  18.    repeat :- repeat.
  19.  
  20.    typewriter :- repeat,
  21.                  readchar(C),        /* Read a char and bind it C */
  22.                  upper_lower(C1,C) , /* Convert C to upper case   */
  23.                  write(C1),
  24.                  char_int(C,13).     /* Is C = ASCII 13? 
  25.                                         This call will fail until a <CR> is
  26.                                         hit.  When the user presses <CR>,
  27.                                         the loop will finally succeed,
  28.                                         ending the repeat/fail process.
  29.                                      */
  30. Goal
  31.    makewindow(1,2,3," Typewriter ",0,0,25,80) ,
  32.    typewriter.
  33.