title: Reading a matrix from a file with Lisp
body: <p>I'm starting with Lisp and I have quite a problem trying to read a matrix from a file to program the A-star algorithm.
  The file I should read has at the top of the file the number of rows and the number of columns, and I must save both in a couple of global variables (<em>N</em> and <em>M</em>). The file format should be something like this:</p>
  
  <pre><code>ROWS
  5
  COLUMNS
  5
  MATRIX
  1 1 1 1 1
  1 1 0 1 1
  1 1 0 0 1
  1 1 0 0 1
  1 1 1 0 1
  START
  4 2
  GOAL
  4 4
  </code></pre>
  
  <p>And my code at the moment is like this (It's probably quite lame, by the way)</p>
  
  <pre><code>(defvar *N*)
  (defvar *M*)
  (defvar *Goal*)
  (defvar *Start*)
  (defvar *Matrix*)
  
  (defun read-matrix (file)
    (let ((in (OPEN file :DIRECTION :INPUT)))
      (read-line in nil) 
      (SETQ *N* (parse-integer (read-char in)))
      (read-line in nil)
      (read-line in nil)
      (SETQ *M* (parse-integer (read-line in)))
      (read-line in nil)
      (read-line in nil)
      (SETQ *Matrix* (MAKE-ARRAY '(*N* *M*) :initial-element 1))
      (loop for i from 0 to *N*
          do (loop for j from 0 to *M*
                 do (SETF (AREF *Matrix* i j)
                      (read-char in))))
      (read-line in nil)
      (SETQ *Start* (read-line in))
      (read-line in nil)
      (SETQ *Goal* (read-line in))))
  </code></pre>
  
  <p>I'd be really grateful if anybody could help me. </p>