Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!cornell!rochester!daemon
From: stuart
Newsgroups: comp.lang.prolog
Subject: Need style advice
Message-ID: <1988Jul14.231619.22145@cs.rochester.edu>
Date: 15 Jul 88 03:16:19 GMT
Organization: U of Rochester, CS Dept, Rochester, NY
Lines: 37

From: stuart

I'd like some advice about how to clean up a relation.

foo_value/2 is intended to be a proper, single-valued, function.
Several clauses can be satisfied at the same time, so I'm depending on
the lexical ordering of clauses and the use of cut to give the proper
precedence among multiple satisfiable clauses and enforce a single
value.

  foo_value(X, value_1) :- forced_to_be_1(X), !.

  foo_value(X, value_2) :- relation_one(X, Y), not(forced_to_be_1(Y)), !.
  foo_value(X, value_2) :- relation_two(X, Y), foo_value(Y, value_2), !.

  foo_value(X, value_1) :- relation_one(X, Y), forced_to_be_1(Y), !.
  foo_value(X, value_1) :- relation_two(X, Y), foo_value(Y, value_1), !.

  foo_value(X, value_3).

Is there a better way to get the same effect?  "Better" can mean
more efficient, more aesthetic, closer to purely logical, fewer uses
of cut and not, or whatever metric experienced Prolog users use.  :-)

Some other notes:
  relation_two/2 contains no cycles.  (It is neither reflexive
  nor symmetric, nor are there any longer sequences XrY YrZ ... WrX.)

  forced_to_be_1/1 is a collection of ground literals.

  relation_one/2 and relation_two/2 can satisfy multiple second
  arguments for a fully instantiated first argument.

  It would be nice, but not essential, if both arguments could be
  given as unbound variables.  Normally, I try to satisfy
  foo_value(literal, V).

Stu Friedberg  stuart@cs.rochester.edu  {ames,cmcl2,rutgers}!rochester!stuart