Re: Prolog type overloading
- From: "Mauro DiNuzzo" <picorna@xxxxxxxxx>
- Date: Thu, 29 Jun 2006 09:30:30 +0200
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)
.
- Follow-Ups:
- Re: Prolog type overloading
- From: Mauro DiNuzzo
- Re: Prolog type overloading
- References:
- Prolog type overloading
- From: George
- Prolog type overloading
- Prev by Date: Re: Prolog type overloading
- Next by Date: Re: Prolog type overloading
- Previous by thread: Re: Prolog type overloading
- Next by thread: Re: Prolog type overloading
- Index(es):
Relevant Pages
|
|