Subject: Printing to a file

From: Fraser Mathieson {Students} <[email-masked]>
Date: Mon, 13 Mar 2000 12:19:42 -0000

Hi again,

I sent an e-mail last week, and now I have got a new problem on the program
I am trying to write.

This time its:

	Search the list of train journeys and print out in a different file,
all the train journeys 	from one station to the next, including the
intermediate stations.

The journeys are, again, in the form of:
	train(['Stirling',849,'Glasgow',935]).
	train(['Stirling',905,'Edinburgh',958]).
	train(['Aberdeen',705,'Dundee',825,'Perth',847,'Stirling',
		 919,'Glasgow',950]).
	train(['Stirling',935,'Edinburgh',1028]).
	train(['Stirling',949,'Glasgow',1035]).
	train(['Stirling',1005,'Edinburgh',1100]).
	train(['Inverness',720,'Perth',928,'Stirling',1008,
		 'Edinburgh',1047,'London',1600]).

The precdicate:
	directJourneys(City1,City2)
must be used.

I have used the following, and it is not doing the right thing.
 	from(X,[X|L],[X|L1]).
	from(X,[X|L,S) :- H \= X, from(X,L,S).
	to(X, [X|_], [X|_]).  % discard the part after X
	to(X, [H|L], [H|L1]) :-  % keep H in the answer
      	  H \= X, to(X,L,L1).

	directJourneys(City1,City2) :-
		train(List),
		tell('assignment.txt'),
		fromTo(City1,City2,X,S),
		fail,
		told.

	fromTo(City1,City2,X,S) :-
		from(City1,X,S1),
		to(City2,S1,S),
		write(S), nl.

Could anybody tell me how to sort this.

Cheers

Fraser Mathieson
([email-masked])