CLISP : Reading a file

See the references at the end of this post for details related with this topic. It will help you learn all the nuts and bolts of streams handling in clisp.

Now I want to read this file which contain following information. To be precise, its a graph written in a format which resembles lisp code.

(a) (b c d)
(b) (a c d)
(c) (a b d)
(d) (b c)

It graph file can be very complicated. Here is what I did to read this file. What each line does in code can be googled out easily. Just put lisp with the keyword while searching.

; Dilawar Singh
; 2011, IIT Bombay
; Dept of Electrical Engineering.

;; This function will open a file and read a graph.
;; TODO : Graph Format.

;;;; TODO: File name should be passed from terminal. For now we assume that file
;;;; name is 'graph.txt' by dafault and it reside is the same directory as of this
;;;; file containing source code.

  (graph-stream "./graph.txt"
                :direction :input
                :if-does-not-exist :create)
  (loop for line = (read-line graph-stream nil 'end-of-graph)
        until(eq line 'end-of-graph)
        do( print line))) ;; We need to something more.

References :






About Dilawar

Graduate Student at National Center for Biological Sciences, Bangalore.
This entry was posted in LISP, Programming and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s