🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #2212

next_to code question

#2212
From: Art Winterbauer
Date: Thu, 17 Dec 1992 20:49
26 lines
1343 bytes
Here's some code I don't understand.

append([],L,L) :- !.
append([X|L1],L2,[X|L3]) :- append(L1,L2,L3). 

next_to(El1,El2,List) :- append(_,[El1,El2|_], List).

In the second edition of Clocksin and Mellish, p. 150, they state that the
above definition of "next_to" is an example of relational programming.  By
typing:

next_to(a,b,[c,d,a,b,q]).

for example, you'll get a true response.  I don't know why it works,
probably because I never could quite understand how append works.  Since
I'm missing an important concept here, could someone explain to me (and the
net) why it works?  The debugger in the Prolog interpreter (Amziod) I have
doesn't seem to go into enough detail to show me exactly what's happening.

Thanks,

Art
-- 
Art Winterbauer  N0OQS
Internet:  awinterb@du.edu OR awinterb@diana.cair.du.edu
Packet:    n0oqs @ w0gvt.#neco.co.usa 
Technical Details
Message-ID: <1992Dec17.204918.6730@mercury.cair.du.edu>
Path: arc1-ca.pugleaf.net!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

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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
From: awinterb@diana.cair.du.edu (Art Winterbauer)
Newsgroups: comp.lang.prolog
Subject: next_to code question
Message-ID: <1992Dec17.204918.6730@mercury.cair.du.edu>
Date: 17 Dec 92 20:49:18 GMT
Sender: news@mercury.cair.du.edu (netnews)
Organization: University of Denver, Denver, Colorado
Lines: 26