Re: Prolog type overloading



Lekeas GK writes:
Jussi Piitulainen wrote:
George writes:
....
I would like to define a predicate with the same name (next) but
with the following logic: if next succeeds with a list, check
whether the player I pass as an argument is member of that list. I
wrote it as:

next(P):-
next([S]),
member(P,[S]).

However, this results in infinite looping. Is there a better of
doing it or telling Prolog not to invoke next without a list as
the parameter?

The better way is to use different names for different
predicates.

I know - it is just that I am extending a single-user game programme
to accomodate multiple users and I thought it would be nice if I
could use the same name for predicates meant to be doing the same
thing. I will have a good read to your suggestions and get back. The
key issue is you can not tell Prolog if P is a list, follow these
rules else follow some others, correct?

Correct when P is a variable. If P is even partially instantiated,
unification may provide a way, but things can get confusing, which
I tried to demonstrate.

The situation is different in a typed setting, where P would be
known to be a list or not, even when uninstantiated. That does not
apply to Prolog. I would worry about readability even if it did.
Those two predicates are not really doing the same thing.
.



Relevant Pages

  • Re: OO versus RDB
    ... There is a very simple mapping from RM to PROLOG. ... a representation based on predicates, ... 'connection' comes from the fact that PROLOG stores rules about facts ...
    (comp.object)
  • Re: OO versus RDB
    ... There is a very simple mapping from RM to PROLOG. ... store knowledge using predicates. ... applied to a physical representation of a relational model. ...
    (comp.object)
  • Re: Prolog, memory management and memory leaks
    ... It depends on what you mean by a memory leak. ... Did the programmer mess up, ... the Prolog implementation you are working with). ... non-deterministic predicates in not always perfect. ...
    (comp.lang.prolog)
  • Re: Cross-Compiler development (MasterProlog/SWI/SICStus)
    ... In most Prolog applications, there are usually a small set of ... top predicates and a bigger number of auxiliary predicates. ... of the object encapsulating them. ... the configuration file for your Prolog compiler, ...
    (comp.lang.prolog)
  • Re: What should the semantics of hierarchical modules be?
    ... > Brian Hulley wrote: ... >>>the pure Prolog. ... But Prolog) Predicates are global and there are no objects or types to ... and write "foo" and let prolog discover what I meant by searching" ...
    (comp.lang.prolog)