For Programmers: Free Programming Magazines  


Home > Archive > Prolog > May 2004 > multiple hits of same result ? - newbie









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 hits of same result ? - newbie
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).*/







Nick Wedd

2004-05-04, 2:59 pm

In message <4095ed27$0$16589$5a62ac22@freenews.iinet.net.au>, Chris
Vasey <cvaseyusefirst6chars@iinet.net.au> writes
>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).


The above three clauses give the names of three types of cuisine. I
don't see the point of this. You will only be using 'buffet' etc. in
contexts where a cuisine type is expected anyway.

The same applies to the following predicates.

>location(claremont).
>
>location(subiaco).
>
>location(burswood).
>
>pricing(exculsive).


(I wouldn't normally bother to point out a spelling mistake. But your
Prolog system will expect things to be spelled consistently.)

>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).


The above clause says that 'exclusive' is a type of pricing if 30 is a
type of 'avg_dish_cost' AND 'imported is a type of 'wine_type' AND 'no'
is a type of 'byo'.
These tail goals all succeed, always. So this predicate succeeds,
always. So pricing(exclusive) succeeds, always. Moreover,
pricing(exculsive) also succeeds, always. I am sure this is not what
you want.
Also, those ANDs are too restrictive. How about a restaurant with cheap
dishes but imported wine?


>pricing(moderate):-
>
>avg_dish_cost(20),
>
>wine_type(local),
>
>byo(yes).
>
>
>
>/* create a restuarant*/
>
>restaurant(atrium_buffet):-
>
>cuisine(buffet),
>
>pricing(exclusive),
>
>location(burswood).


This does not create a restaurant. It says that burswood is a
restaurant if those three tail goals succeed. And they do succeed.

>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).*/


I think that what you want will look more look this:


wine_type( burswood, imported ).
cuisine( burswood, buffet ).

pricing( Restaurant, exclusive ) :-
wine_type( Restaurant, imported ).

etc.


Nick
--
Nick Wedd nick@maproom.co.uk
Sponsored Links







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

Copyright 2008 codecomments.com