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

  1. /*
  2.    Turbo Prolog 2.0 Chapter 8, Example Program 9
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5.    
  6. */
  7.    
  8. domains
  9.    llist = l(list); s(symbol); i(integer); c(char); t(string)
  10.    list = llist*
  11.  
  12. predicates
  13.    append(list, list, list)
  14.  
  15. goal
  16.    makewindow(1, 7, 7, "answer", 15, 0, 8, 80),
  17.  
  18. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  19.  * Note how you can use the same code but need functors  *
  20.  * append([ likes, [bill, mary] ], [ bill, sue ], Ans)   *
  21.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  22.  
  23.    append([s(likes), l([s(bill), s(mary)])], [s(bill), s(sue)],
  24. Ans),
  25.    write("FIRST  LIST: ", Ans), nl, nl,
  26.  
  27. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  28.  * The trick is to write the list first, then add the functors *
  29.  *   append([apple, [ [ [47], '\1'] ],                       *
  30.  *   [ [ [ "This is a string", b, 7, 'W'] ], bee],           *
  31.  *   [ 'c' ], Ans2)                                          *
  32.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  33.       append([l([s("This"),s("is"),s("a"),s("list")]), s(bee)], [c('c')], Ans2),
  34.       write("SECOND LIST: ", Ans2), nl.
  35.  
  36. clauses
  37.    /* Concatenate two lists */
  38.    append([], L, L).
  39.    append([X|L1], L2, [X|L3]) :- append(L1, L2, L3).
  40.