home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / prolog / 2253 < prev    next >
Encoding:
Internet Message Format  |  1992-12-18  |  1.3 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!usenet.coe.montana.edu!saimiri.primate.wisc.edu!copper!mercury.cair.du.edu!diana.cair.du.edu!awinterb
  2. From: awinterb@diana.cair.du.edu (Art Winterbauer)
  3. Newsgroups: comp.lang.prolog
  4. Subject: next_to code question
  5. Message-ID: <1992Dec17.204918.6730@mercury.cair.du.edu>
  6. Date: 17 Dec 92 20:49:18 GMT
  7. Sender: news@mercury.cair.du.edu (netnews)
  8. Organization: University of Denver, Denver, Colorado
  9. Lines: 26
  10.  
  11. Here's some code I don't understand.
  12.  
  13. append([],L,L) :- !.
  14. append([X|L1],L2,[X|L3]) :- append(L1,L2,L3). 
  15.  
  16. next_to(El1,El2,List) :- append(_,[El1,El2|_], List).
  17.  
  18. In the second edition of Clocksin and Mellish, p. 150, they state that the
  19. above definition of "next_to" is an example of relational programming.  By
  20. typing:
  21.  
  22. next_to(a,b,[c,d,a,b,q]).
  23.  
  24. for example, you'll get a true response.  I don't know why it works,
  25. probably because I never could quite understand how append works.  Since
  26. I'm missing an important concept here, could someone explain to me (and the
  27. net) why it works?  The debugger in the Prolog interpreter (Amziod) I have
  28. doesn't seem to go into enough detail to show me exactly what's happening.
  29.  
  30. Thanks,
  31.  
  32. Art
  33. -- 
  34. Art Winterbauer  N0OQS
  35. Internet:  awinterb@du.edu OR awinterb@diana.cair.du.edu
  36. Packet:    n0oqs @ w0gvt.#neco.co.usa 
  37.