Jump to content

Help with prolog question....!!!

- - - - -

  • Please log in to reply
3 replies to this topic

#1
thedevil

thedevil

    Newbie

  • Members
  • Pip
  • 4 posts
Predicates
is_a(X,Y) X is a doctor/handyman
drives(X,Y) X drives Y

We are given that a doctor drives a sportscar and a handyman drives a 4WD

is_a(john,doctor).
is_a(david,handyman).

Now i want the code decide what kind of car john/david are driving....

I tried doing it...

drives(X,sportscar) :- is_a(X,doctor).
drives(Y,4WD) :- is_a(Y,handyman).


What am i doing wrong ??


?- drives(john,fourwd).
true .

?- drives(john,sportscar).
true .

?- drives(david,fourwd).
true .

?- drives(david,sportscar).
true .

Thanks....

#2
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts

Quote

drives(Y,4WD) :- is_a(Y,handyman).
This is incorrect. the second argument should be fourwd. Using this, it works fine for me:

3 ?- drives(john,fourwd).

false.


4 ?- drives(john,sportscar).

true .


5 ?- drives(david,fourwd).

true.


6 ?- drives(david,sportscar).

false.


#3
thedevil

thedevil

    Newbie

  • Members
  • Pip
  • 4 posts
Thanks for the help...

I have one more question.... Sorry if i'm bothering you too much....

In the same question....

I have another person called Jacob who drives the same type of car as david....

Thats alls that given... nad i'm really confused on what to do....

#4
thedevil

thedevil

    Newbie

  • Members
  • Pip
  • 4 posts
actuall figured it out...


drives(barney,Y) :-
is_a(X,handyman),
drives(X,Y).




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users