From: Fernando Gonzalez del Cueto
Subject: Reading and then Writing to a file - small newbie question - please
Date: 
Message-ID: <6ar56n$3ta$1@hp.fciencias.unam.mx>
I've got to read a text file using LISP (mulisp or common lisp)
and then write another text file. What commands should I use?

Thank you very much.

Fernando.
From: marisa
Subject: Re: Reading and then Writing to a file - small newbie question - please
Date: 
Message-ID: <34D22CBA.A52936E8@kabelfoon.nl>
Fernando Gonzalez del Cueto wrote:

> I've got to read a text file using LISP (mulisp or common lisp)
> and then write another text file. What commands should I use?
>
> Thank you very much.
>
> Fernando.

  Simple: first you have to open the file (sort of assigning it to a
logical name, like in Pascal or C). Lisp works with "streams", which
represent any kind of data source or sink. The screen is considered as a
stream, for example.
If you are in a DOS evironment, and say your file is called
c:\mydir\myfile.txt then you type: (setf my-stream (open
"c:\\mydir\\myfile.txt" :direction :input))
This opens the file and assigns it to the logical name my-stream.
Now you simply type (read my-stream) and you get the first word in the
text file.
This will give an error at the end of the file, so if you want to
prevent it, type:
(read my-stream nil nil) which will return nil instead when the EOF is
reached.
If you want to write to a different file, then assign it again with the
open comman, this time using the keyword :output. You may also use :io
for an input/output file.
(setf my-second-stream (open "c:\\mydir\\myfile2.txt" :direction
:output))

To write to this file you type: (format my-second-stream "~A" 'a-word)

You can also use the command print, or princ, or prin1, etc... Also look
at all the possibilities of the command format, which are great.
Hope this helps.