I'm starting to learn Prolog, but I cannot find any examples on what I want to do: a list that contains several other lists; is it possible?
Something like this: [ [1,1,1], [2,2,2], [3,3,3] ].
Thank you in advance.
I'm starting to learn Prolog, but I cannot find any examples on what I want to do: a list that contains several other lists; is it possible?
Something like this: [ [1,1,1], [2,2,2], [3,3,3] ].
Thank you in advance.
Try typing at the prompt X = [ [1,1,1], [2,2,2], [3,3,3] ].. Prolog will type it back to you -- i.e. it accepts this as a valid input.
The following are all different ways to specify the same list X:
X = [ [1,1,1], [2,2,2], [3,3,3] ].
X = [ [1,1,1], [2,2,2] | [ [3,3,3] ] ].
X = [ [1,1,1] | [ [2,2,2], [3,3,3] ] ].
A = [1,1,1], X = [A | [ [2,2,2], [3,3,3] ] ].
A = [1,1,1], B = [ [2,2,2], [3,3,3] ], X = [A | B].
A = [1 | T], T = [1,1], B = [ [2,2,2], [3,3,3] ], X = [A | B].
T = [1,1], B = [ [2,2,2], [3,3,3] ], X = [A | B], A = [1 | T].
This shows how to construct the lists by bits and pieces. No "recursivity" required for that, just plain specification and construction; or construction and specification, the order does not matter.
OK so I managed to do the following:
?- findall([NAME,POST,TIMEFLIGHT], pilot(_,NAME,POST,_,_,TIMEFLIGHT,_), Xs),
show(Xs).
show([]):-!.
show([Head|Tail]):-
write(Head),nl,
show(Tail).
which gives me what I wanted, wich is this:
Xs = [ [Joe, Pilot, 100], [Stan, Co-Pilot, 300], [Steve, Pilot, 150] ].