Re: Prolog type overloading



Hi!
I'd like some type checking into the prolog standard...
In fact I wrote a simply script based on term_extension/3 predicate to
handle that issue.
On the other hand you can just do type checking into the clause body, as:

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

Regards,
/\/\


"George" <me@xxxxxx> ha scritto nel messaggio
news:Pine.GSO.4.58.0606281101110.8172@xxxxxxxxxxxxxxxxxxxxxx
Dear All,

I am wondering whether it is possible to define one predicate in Prolog
that takes two different data types as parameters, but has the same number
of arguments.

As an example, I have a predicate that tells me who is to play next in a
game. If I have in my database next([john,peter]), it means that john and
peter are next to make a move.

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?

Thanks,
George

Computers are useless. They can only give you answers.
Pablo Picasso (1881-1973)



.



Relevant Pages

  • Re: Sublists question
    ... I do not really get what the predicate means or does. ... >>helps just to write the predicate out clearly in natural language, ... >>then translate into Prolog. ... more as a functional programming language than as a logic ...
    (comp.lang.prolog)
  • Re: Prolog module system
    ... I think prolog offers so much freedom that one can build its own ... Both modules define a member/2 predicate, ... this leads to a name conflict. ... shaky ground as current module systems (look at the issues with e.g. ...
    (comp.lang.prolog)
  • Re: Prolog, memory management and memory leaks
    ... predicate is executed that solves constraint problem. ... In some circumstances, this server leaks memory. ... "Understanding Memory Management in Prolog ... There is not just one garbage collector in Prolog. ...
    (comp.lang.prolog)
  • Re: Prolog module system
    ... my experiment with oop and modules has almost reach a point ... On the other hand, when I came to Prolog as a logic programming language, I ... Consider the length/2 predicate. ... OO systems have much more complex built-in lookup rules. ...
    (comp.lang.prolog)
  • Re: Prolog module system
    ... We talked a bit about this on the Prolog standardization forums but is ... Both modules define a member/2 predicate, ... this leads to a name conflict. ... shaky ground as current module systems (look at the issues with e.g. ...
    (comp.lang.prolog)