For Programmers: Free Programming Magazines  


Home > Archive > Prolog > May 2004 > multiple results? newbie here









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author multiple results? newbie here
Chris Vasey

2004-05-04, 2:59 pm

hi everyone

i'm learning prolog for uni and have a problem:

bassically when i call "restuarant(X)." i get 2 hits the same restaurant
that has "moderate" as it's pricing value

any help guys? it's very strange. also i think it's affecting my "asking
user" predicates

any help would be grand, cheers.

heres the code:

cuisine(buffet).

cuisine(pizza_pasta).

cuisine(thai).

location(claremont).

location(subiaco).

location(burswood).

pricing(exculsive).

pricing(moderate).

avg_dish_cost(20).

avg_dish_cost(30).

wine_type(local).

wine_type(imported).

byo(yes).

byo(no).

/*pricing information*/

pricing(exclusive):-

avg_dish_cost(30),

wine_type(imported),

byo(no).

pricing(moderate):-

avg_dish_cost(20),

wine_type(local),

byo(yes).



/* create a restuarant*/

restaurant(atrium_buffet):-

cuisine(buffet),

pricing(exclusive),

location(burswood).

restaurant(allegro_pizza):-

cuisine(pizza_pasta),

pricing(moderate),

location(claremont).

restaurant(amarinthai):-

cuisine(thai),

pricing(moderate),

location(subiaco).

/* asking the user

location(X):- ask(location,X).

cuisine(X):- ask(cuisine,X).

pricing(X):- ask(pricing,X).

ask(Attr, Val):-

write(Attr:Val),

write('?'),

read(yes).*/








Bart Demoen

2004-05-04, 2:59 pm

Chris Vasey wrote:
> hi everyone
>
> i'm learning prolog for uni and have a problem:
>
> bassically when i call "restuarant(X)." i get 2 hits the same restaurant
> that has "moderate" as it's pricing value
>
> any help guys? it's very strange. also i think it's affecting my "asking
> user" predicates
>


Let me keep of your program what causes the behaviour:


> pricing(moderate).
>
> pricing(moderate):-
>
> avg_dish_cost(20),
>
> wine_type(local),
>
> byo(yes).



You have thus defined two way to prove the truth of the literal pricing(moderate).
Prolog explores both.
At the Prolog toplevel, the query

?- pricing(moderate).

will give you only one Yes, because toplevels usually do that with ground queries.
But if you ask

?- pricing(X).

you should get the answer X = moderate twice.

Cheers

Bart Demoen
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com