Article View: comp.lang.prolog
Article #1083Re: Having trouble with disjunction
From: Richard A. O'Keefe
Date: Wed, 15 Aug 1990 04:59
Date: Wed, 15 Aug 1990 04:59
44 lines
1805 bytes
1805 bytes
In article <90226.091749F0O@psuvm.psu.edu>, F0O@psuvm.psu.edu writes:
> gofirst(Player) :-
> random(RandNum),
> RandNum < 0.5, Player = computer ;
> RandNum >= 0.5, Player = opponent.
>
> When I tried to run the program, I got the message 'Free variables
> not allowed here', at Player = opponent.
> Is this a quirk of PDC prolog, or don't I fully understand disjunction?
This is easily the best thing I have ever heard about PDC Prolog.
Your problem is that you have a terrible layout convention.
Let's put your code through a Prolog pretty-printer and see what comes out:
gofirst(Player) :-
( random(RandNum),
RandNum < 0.5,
Player = computer
; RandNum >= 0.5,
Player = opponent
).
See what's going on?
Use this indentation rule: always write disjunctions as
( <disj1>
; <disj2>
...
; <disjn>
)
exactly like you'd write an Ada if statement, with "(" acting like "if",
"->" [when using it] acting like "then", ";" acting like "else if" or
"else", and ")" acting like "end if". Following that rule, and writing
what you meant, we get
gofirst(Player) :-
random(RandNum),
( RandNum < 0.5,
Player = computer
; RandNum >= 0.5,
Player = opponent
).
--
The taxonomy of Pleistocene equids is in a state of confusion.
Technical Details
Message-ID:
<3567@goanna.cs.rmit.oz.au>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!know!samsung!munnari.oz.au!goanna!okReferences:
<90226.091749F0O@psuvm.psu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!know!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: Having trouble with disjunction Message-ID: <3567@goanna.cs.rmit.oz.au> Date: 15 Aug 90 04:59:42 GMT References: <90226.091749F0O@psuvm.psu.edu> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 44