Re: query in file

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Tue 15 Jul 2003 05:43:13 PM GMT
Message-ID: <3F143D31.7883A0DD@icparc.ic.ac.uk>
Kourosh Khoshelham wrote:
> 
> Hello list,
> i have a program which works fine but it looks odd since i have to enter a
> very long query in query entry box (in windows based eclipse). how can i put
> the query inside the file and get its results in the interface? it comes
> like this:
> 
> ?- oLine(L1,C1,P1), visible(L1),
>         oLine(L2,C2,_), visible(L2), not member(L2,[L1]), member(L2,C1),
>         oLine(L3,C3,_), visible(L3), not member(L3,[L1,L2]), member(L3,C1), not
> member(L3,C2),
>         oLine(L4,_,P4), visible(L4), not member(L4,[L1,L2,L3]), member(L4,P1),
> member(L4,C3), not member(L4,C2),
>         oLine(L5,_,_), visible(L5), not member(L5,[L1,L2,L3,L4]), member(L5,P1),
> member(L5,P4).


To get the *exact* same output in the interface, you could
add to your file a predicate like

query1(L1,L2,L3,L4,L5,C1,C2,C3,P1,P4) :-
	oLine(L1,C1,P1), visible(L1),
        oLine(L2,C2,_), visible(L2), not member(L2,[L1]), member(L2,C1),
        oLine(L3,C3,_), visible(L3), not member(L3,[L1,L2]), member(L3,C1), not member(L3,C2),
        oLine(L4,_,P4), visible(L4), not member(L4,[L1,L2,L3]), member(L4,P1), member(L4,C3), not member(L4,C2),
        oLine(L5,_,_), visible(L5), not member(L5,[L1,L2,L3,L4]), member(L5,P1), member(L5,P4).

and then type into the query box:

?- query1(L1,L2,L3,L4,L5,C1,C2,C3,P1).


Obviously, remembering the exact number of arguments is painful,
so you may want to group them, e.g.

query2([L1,L2,L3,L4,L5],[C1,C2,C3],[P1,P4]) :-
	oLine(L1,C1,P1), visible(L1),
	...

and then invoke the simpler query

?- query2(Ls,Cs,Ps).


To make you code independent of the development interface,
you should eventually let your program do the output itself, e.g.

query3 :-
	oLine(L1,C1,P1), visible(L1),
	...,

	writeln("Ls" = [L1,L2,L3,L4,L5]),	% or printf
	writeln("Cs" = [C1,C2,C3]),
	writeln("Ps" = [P1,P4]).



-- 
 Joachim Schimpf              /             phone: +44 20 7594 8187
 IC-Parc                     /      mailto:J.Schimpf@imperial.ac.uk
 Imperial College London    /    http://www.icparc.ic.ac.uk/eclipse
Received on Tue Jul 15 18:44:32 2003

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:25 PM GMT GMT