🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: gmane.comp.ai.prolog.swi
1 messages
1 total messages Started by "Shira Rotman" Thu, 11 Apr 2002 23:41
[SWIPL]
#2
Author: "Shira Rotman"
Date: Thu, 11 Apr 2002 23:41
34 lines
1018 bytes
Hello,

I have this code:

swap([],[]).
swap([X],[X]).
swap([X,Y|L1],[X,Y|L2]):-X=<Y,swap([Y|L1],[Y|L2]).
swap([X,Y|L1],[Y,X|L2]):-X>Y,swap([X|L1],[X|L2]).

When I try to run it by typing: "?-swap([2,5,4,7,6],X).", it first gets to
line 3 and calls swap([5,4,7,6],[5|_G367]). Then it checks if 5=<4 and
fails, but it doesn't continue to line 4 to check if 5>4, but returns to the
original call (with [2,5,4,7,6]) and then continues to line 4, checks if
2>5, fails and prints "No".

I don't understand why it doesn't continue to line 4 to check if 5>4 after
it fails in line 3 in the second call. Does somebody have a solution?

Thanks.



----------------
* To UNSUBSCRIBE, please use the HTML form at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist

or send mail to prolog-request@swi.psy.uva.nl using the Subject: "unsubscribe"
(without the quotes) and *no* message body.

** An ARCHIVE of this list is maintained at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads