Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lists searching

Status
Not open for further replies.

madarb

Programmer
Jan 4, 2007
13
GR
i have the following problem:

i have facts of flights using lists and im trying to find a way to search inside lists.

here's how the facts are described:

flight(london,milan,
[[times(depart(8),arrive(11)),code(ba510),mo,tu,we,th,fr,sa,su],
[times(depart(11),arrive(14)),code(az459),mo,tu,we,th,fr,sa,su]]).


flight(athens,zurich,
[[times(depart(11),arrive(13)),code(oa322),tu,th]]).

flight(london,edinburgh,
[[times(depart(9),arrive(10)),code(ba4732),mo,tu,we,th,fr,sa,su],
[times(depart(11),arrive(12)),code(ba4752),mo,tu,we,th,fr,sa,su],
[times(depart(18),arrive(19)),code(ba4822),mo,tu,we,th,fr]]).

these are not all,but generally theyre all in this fashion.
so for each pair of cities i have a list containing one to three lists with flight info,depending on how flights there are for these two cities.

i need to find a way to search the "outter" list in order to find flight info.the problem is my facts are not all the same as some have 1 flight and others 2 or 3.can anyone help me?
it'd be much appreciated.thank you.

 

infoFlight(D,P,L):-findall([D,P,X],flight(D,P,X),L).

%-----------
or like this, if you can see all
:-dynamic(fly).

infoFlight(D,P,L):-findall([D,P,X],flight(D,P,X),L),assert(fly([L])).

listing(fly).
 
thanks a lot for the reply but i really dont understand what it is you're doing.
could you explain what findall and listing does?
 
explain what findall and listing does:

findall: Retrieves all the elements that match the conditions defined by the specified predicate flight(D,P,X).

listing: type listing(fligth)and you will see your database
 
explain what findall and listing does:

findall: Retrieves all the elements that match the conditions defined by the specified predicate flight(D,P,X).

listing: type listing(fligth)and you will see your knowledge base
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top