I'm having some problems with a simple program in Prolog. I have two different groups, and I would like to attach an element of one group to another, without directly modifying the facts (eg: Toronto = USA).
country(usa, northamerica).
country(canada, northamerica).
city(chicago, usa).
city(newyork, usa).
city(losangeles, usa).
city(dallas, usa).
city(miami, usa).
city(lasvegas, usa).
city(seattle, usa).
city(toronto, canada).
city(vancouver, canada).
city(ottawa, canada).
city(richmond, canada).
city(winnipeg, canada).
city(edmundston, canada).
city(hamilton, canada).
trip(john, usa).
trip(jack, canada).
In this example, John traveled to seven cities in the USA, while Jack traveled to others seven cities in Canada.
However, John recently traveled to Toronto. I would like to reach the following result:
? - trip_plus(X, john).
X = chicago;
X = newyork;
X = losangeles;
X = dallas;
X = miami;
X = lasvegas;
X = seattle;
X = toronto;
?- yes
I tried many times unsuccessfully to get the result above. The closest I could get was using the following:
country(C).
city(Y).
trip(T).
trip_plus(X, T) :- city(Y, C), trip(T, C).
What am I doing wrong?
Thanks mates.