/* Se numeran los elementos leídos a partir de N */
contar(N):-
	read(Termino),
	mostrar(Termino,N).

mostrar(end_of_file,_):- !.

mostrar(Termino,N):-
	write(N),
	tab(2),
	write(Termino),
	nl,
	N1 is N + 1,
	contar(N1).

program(File):- 
	/* Save for later the previous current input device */ 
	current_input(Old), 		

	/* Open the file and set as current input */ 
	open(File,read,Stream), 
	set_input(Stream),				

	/* Process the file */
	contar(1),

	/* Close the stream */ 
	close(Stream),		

	/* Restore the previous current input device */ 
	set_input(Old). 			
			
