title: How to read a csv file into a list of lists in SWI prolog where the inner list represents each line of the CSV?
body: <p>I have a CSV file that look something like below: i.e. not in Prolog format</p>
  
  <pre><code>james,facebook,intel,samsung
  rebecca,intel,samsung,facebook
  Ian,samsung,facebook,intel
  </code></pre>
  
  <p>I am trying to write a Prolog predicate that reads the file and returns a list that looks like</p>
  
  <pre><code>[[james,facebook,intel,samsung],[rebecca,intel,samsung,facebook],[Ian,samsung,facebook,intel]]
  </code></pre>
  
  <p>to be used further in other predicates.</p>
  
  <p>I am still a beginner and have found some good information from SO and modified them to see if I can get it but I`m stuck because I only generate a list that looks like this</p>
  
  <pre><code>[[(james,facebook,intel,samsung)],[(rebecca,intel,samsung,facebook)],[(Ian,samsung,facebook,intel)]]
  </code></pre>
  
  <p>which means when I call the head of the inner lists I get <code>(james,facebook,intel,samsung)</code> and not <code>james</code>.</p>
  
  <p>Here is the code being used <code>:-</code> (seen on SO and modified)</p>
  
  <pre><code>stream_representations(Input,Lines) :-
      read_line_to_codes(Input,Line),
      (   Line == end_of_file 
      -&gt;  Lines = []
      ;   atom_codes(FinalLine, Line), 
          term_to_atom(LineTerm,FinalLine), 
          Lines = [[LineTerm] | FurtherLines],
          stream_representations(Input,FurtherLines) 
      ).
  </code></pre>
  
  <pre><code>main(Lines) :- 
      open('file.txt', read, Input), 
      stream_representations(Input, Lines), 
      close(Input).
  </code></pre>