title: Prolog, Why does my predicate print the output of `write()` multiple times?
body: <p>I having a hard time understand what my predicate <code>fly(....)</code> is outputting. When I consult this file and ask the console(SWI-Prolog) <code>flight(city1, city2, A, B)</code> it prints out <code>A=9 B=10</code>. Which I was figuring is a single value for A and B alike. So I then wanted to use the output to finish what I was trying to accomplish; flight planner. But it seems that when I use the same question (<code>flight(city1, city2, A, B)</code>) in a predicate it returns a list. I did not realize this until I tried to write <code>S</code> and/or <code>E</code>. I am printing <code>[1,2,3]</code> in the code below because I was confused why when I only wrote <code>S</code>, and not anything after it, the output was just each value in the list not comma or space separated. So I decided to see how it would write a explicitly defined a list <code>[1,2,3]</code> and printed it. </p>
  
  <p>The output I am receiving </p>
  
  <pre><code>8 ?- fly(city1, city4, 0, 24).
     14[1,2,3]9[1,2,3]
     false.
  </code></pre>
  
  <p>It seems like the line <code>write(S), write([1,2,3]),</code> is being called twice, why is this? </p>
  
  <p>Also, why do I get a single value in the console for <code>A</code> and <code>B</code> but not in my predicate when it is called?</p>
  
  <p>Code verbatim:</p>
  
  <pre><code>% I have no idea what I'm doing.
  % Author: Skeeter
  
  % Total of 5 cities
  city(city1).
  city(city2).
  city(city3).
  city(city4).
  city(city5).
  
  % List of flights
  % flight( StartCity, EndCity, DepartureTime, ArrivalTime)
  % city1 departures
  flight( city1, city2, 09, 10).
  flight( city1, city2, 10, 11).
  flight( city1, city3, 12, 13).
  flight( city1, city4, 14, 15).
  flight( city1, city5, 16, 17).
  % city2 departures
  flight( city2, city1, 09, 10).
  flight( city2, city1, 10, 11).
  flight( city2, city3, 12, 13).
  flight( city2, city4, 14, 15).
  flight( city2, city5, 16, 17).
  % city3 departures
  flight( city3, city1, 09, 10).
  flight( city3, city2, 10, 11).
  flight( city3, city2, 12, 13).
  flight( city3, city4, 14, 15).
  flight( city3, city5, 16, 17).
  % city4 departures
  flight( city4, city1, 09, 10).
  flight( city4, city2, 10, 11).
  flight( city4, city3, 12, 13).
  flight( city4, city3, 14, 15).
  flight( city4, city5, 16, 17).
  % city5 departures
  flight( city5, city1, 09, 10).
  flight( city5, city2, 10, 11).
  flight( city5, city3, 12, 13).
  flight( city5, city4, 14, 15).
  flight( city5, city4, 16, 17).
  
  % city1 arrivals
  flight( city2, city1, 09, 10).
  flight( city2, city1, 10, 11).
  flight( city3, city1, 12, 13).
  flight( city4, city1, 14, 15).
  flight( city5, city1, 16, 17).
  % city2 arrivals
  flight( city1, city2, 09, 10).
  flight( city1, city2, 10, 11).
  flight( city3, city2, 12, 13).
  flight( city4, city2, 14, 15).
  flight( city5, city2, 16, 17).
  % city3 arrivals
  flight( city1, city3, 09, 10).
  flight( city2, city3, 10, 11).
  flight( city2, city3, 12, 13).
  flight( city4, city3, 14, 15).
  flight( city5, city3, 16, 17).
  % city4 arrivals
  flight( city1, city4, 09, 10).
  flight( city2, city4, 10, 11).
  flight( city3, city4, 12, 13).
  flight( city3, city4, 14, 15).
  flight( city5, city4, 16, 17).
  % city5 arrivals
  flight( city1, city5, 09, 10).
  flight( city2, city5, 10, 11).
  flight( city3, city5, 12, 13).
  flight( city4, city5, 14, 15).
  flight( city4, city5, 16, 17).
  
  % is H1 later than X?
  isLater(H1, [X|Y]) :-
  H1 &gt; X.
  
  
  fly(CityFrom, CityTo, StartTime, EndTime) :-
  flight(CityFrom, CityTo, S, E),
  write(S), write([1,2,3]),
  isLater(StartTime, S),
  isLater(EndTime, E).
  </code></pre>