Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!stretch.cs.mun.ca!leif!jgarland From: jgarland@kean.ucs.mun.ca Newsgroups: comp.lang.prolog Subject: Re: Having trouble with disjunction Message-ID: <125275@kean.ucs.mun.ca> Date: 15 Aug 90 00:49:29 GMT References: <90226.091749F0O@psuvm.psu.edu> Organization: Memorial University. St.John's Nfld, Canada Lines: 64 In article <90226.091749F0O@psuvm.psu.edu>, F0O@psuvm.psu.edu writes: The structure: > gofirst(Player) :- > random(RandNum), > RandNum < 0.5, Player = computer ; > RandNum >= 0.5, Player = opponent. > > [Tim] Nice idea, the problem is you're thinking in Pascal. Disjunction works more like a case statement in PDC. I.e. your structure is equivalent to: gofirst(Player) :- random(Ran),Ran < 0.5,Player=computer. gofirst(Player) :- Ran >= 0.5, Player=opponent. Ran is indeed free. Listing 1 clumsily implements your ideas using the cut **************** Listing 1 ******************** predicates gofirst(symbol) clauses gofirst(Player) :- random(Ran),Ran <= 0.5, !, Player = computer; Player = opponent. goal gofirst(Player). *************** end **************** Listing 2 is more elegant if I may say and doesn't mimic Pascal **************** Listing 2 ******************** predicates gofirst(symbol,integer) clauses gofirst(computer,0). gofirst(opponent,1). goal random(2,Ran), %integer random number generator--fast gofirst(Player,Ran). John Garland Bitnet: jgarland@mun Internet: jgarland@kean.ucs.mun.ca