Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding Variables in a Prolog Query

Tags:

lambda

prolog

I am working on an assignment with prolog which involves an airport database (it has airport cities, and flight links which includes airport tax and duration time) and the first question involves queries. We are supposed to write a Prolog query to answer a question, I already know how to answer the question the problem is Prolog is outputing more information then I want. The query I wrote is:

flight(X,_,Y,_,N), N > 180. 

Basically all it does is list out all cities (X is origin flight, and Y is the destination flight and N is duration). I want X and Y but I do not want N. The only way I can think of getting this to work is by wrapping this query in a rule and just having it display X and Y, but since we are not supposed to write rules I am not sure how to get around this. I do not really want an explicit answer just maybe a hint or something.

like image 741
InsigMath Avatar asked Nov 25 '12 19:11

InsigMath


1 Answers

Where possible I prefer use expressions to compact IO

?- forall((flight(X,_,Y,_,N), N > 180),
           writeln((x=X,y=Y))).

for instance, with a different generator

?- forall((member(X,"12"),member(Y,"ab")),writeln((x=X,y=Y))).
x=49,y=97
x=49,y=98
x=50,y=97
x=50,y=98
true.

Of course, to properly indent tables format/2 will do much better...

edit maybe I misunderstood the question, supposing you already considered

query(X,Y) :-
  flight(X,_,Y,_,N), N > 180.
like image 58
CapelliC Avatar answered Oct 14 '22 17:10

CapelliC