🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1027

Re: Having a problem understanding the cut (arrgh!)

#1027
From: jgarland
Date: Sat, 28 Jul 1990 00:38
116 lines
3654 bytes
In article <4921@munnari.oz.au>, ok@mudla.cs.mu.OZ.AU (Richard O'Keefe) writes:
> In article <90207.090559F0O@psuvm.psu.edu>, F0O@psuvm.psu.edu writes:
>> Players in a squash club are divided into three leagues, and players
>> may only challenge members in their own league or the league below,
>> if there is one.
>> 
** stuff deleted about not being able to do this using cuts as the 
** book instructs

>> Where have I gone astray?
> (a) Why use Turbo Prolog when you could use ALS Prolog?

matter of opinion, has been discussed before

> (b) Why use a cut? 
> I've spent about half an hour thinking about this, and I haven't thought
> of any natural or good way of coding it that involves a cut.

quite right
******************************************************
I would like to point out that there is no reason to use cuts in Turbo 
(PDC) Prolog either.  The User's Guide employs a bad example to make a point.
******************************************************

% This program picks out all legal challenges (i.e., x vs. y and y vs. x ).

domains

player = person(integer,symbol)
%               league  name

predicates

nondeterm person(integer,symbol) 
%                league  name    

clauses

%  3 Leagues, 3 Players / league 
%  NOTE:  Each league's list is sorted but programme does not depend on this.

person(1,jim).  person(1,kermit).  person(1,larry).
person(2,allen).  person(2,barry).   person(2,charles).
person(3,xavier).   person(3,yves).    person(3,zachary).

legal_challenges:-

      person(A,X), person(B,Y),

      X<>Y,               % This discards possibility of playing self

      (A-B)<=0,(A-B)>=-1, % Note order of the conditionals here is impt.
      
      write(X," may challenge ",Y),nl,
      fail. 
      
goal

legal_challenges.
****************************************************************************

% This program picks out all legal games ( i.e., x and y may play). 

domains

player = person(integer,symbol)
%               league  name

predicates

nondeterm person(integer,symbol)
%                league  name    

legal_games

clauses

%  Three leagues, 3 Players / league 
%  As above, sorted order within league is arbitrary

person(1,jim).  person(1,kermit).  person(1,larry).
person(2,allen).  person(2,barry).   person(2,charles).
person(3,xavier).   person(3,yves).    person(3,zachary).


legal_games:-   % finds legal games in own league

      person(A,X),person(A,Y),

      X < Y,    % discards reversed game (i.e. where X > Y)

      write(X," and ",Y," may play"),nl,
      fail. 
      
legal_games :-   % finds legal games in lower league

      person(A,X),person(B,Y),
      
      A-B=-1,  % Note that this *both* picks out lower league
               % *and* discards reversed game
         
      write(X," and ",Y," may play"),nl,
      fail.
goal

legal_games.
*************************************************************************

If you still need help on your first problem, give me a
shout by e-mail.


John Garland

Bitnet:    jgarland@mun
Internet:  jgarland@kean.ucs.mun.ca
Technical Details
Message-ID: <108565@kean.ucs.mun.ca>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucsd!usc!wuarchive!uunet!stretch.cs.mun.ca!leif!jgarland
References: <90207.090559F0O@psuvm.psu.edu> <4921@munnari.oz.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucsd!usc!wuarchive!uunet!stretch.cs.mun.ca!leif!jgarland
From: jgarland@kean.ucs.mun.ca
Newsgroups: comp.lang.prolog
Subject: Re: Having a problem understanding the cut (arrgh!)
Message-ID: <108565@kean.ucs.mun.ca>
Date: 28 Jul 90 00:38:43 GMT
References: <90207.090559F0O@psuvm.psu.edu> <4921@munnari.oz.au>
Organization: Memorial University. St.John's Nfld, Canada
Lines: 116