Creating a List in prolog -


i have predicate has following format: pilot( id1, id2 ).

i'm searching multiple values pilot , im able predicate findall, how can go there , use new predicate create list this:

[ pilot( id1, id2 ), pilot( id1, id2 ), pilot( id1, id2 ), pilot( id1, id2 ), ... ]. 

[clarification]

i this: ask id of flight: id

and this: findall( flights( pilots ), flight( id, pilots, _, _, _, _), xs).

and this:

xs = [ flights( 1, 2 ), flights( 4, 7 ), flights( ... ), ... ].

i take information , find resulting pilots associated id of flights. can each pilot , i'm able write() them, problem iss, have multiple same pilots, because of multiple flights, want put of pilots, have structure: pilot(id,a,b,c,d,e), , put of them in list this:

xa = [ pilot(id,a,b,c,d,e), pilot(id,a,b,c,d,e), pilot(id,a,b,c,d,e), ... ] can remove duplicate entries.

the input format of problem not clear. if have 1 predicate each flight-pilot pair, do:

% flight(id, pilot) flight(1, 100).  flight(1, 102). flight(2, 100).  flight(2, 103). flight(3, 102).  flight(3, 103).  flight(3, 104).  :- id=3,                                            % flight id    findall(pilot(pilot), flight(id, pilot), xs),    % find solutions    sort(xs, uniquepilots),                          % remove duplicates    writeln(uniquepilots). 

[pilot(102), pilot(103), pilot(104)]

alternatively, if have single predicate 1 flight , multiple pilots, 1 do:

% flight(id, pilots) flight(1, [100, 102]). flight(2, [100, 103]). flight(3, [102, 103, 104]). flight(3, [100, 102]).  :- id=3,    findall(pilot(pilot), (flight(id, pilots), member(pilot, pilots)), xs),    sort(xs, uniquepilots),    writeln(uniquepilots). 

[pilot(100), pilot(102), pilot(103), pilot(104)]


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -