home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!mimsy!prometheus!media!hqda-ai!grant
- From: grant@pentagon-gw.army.mil (Pete Grant)
- Newsgroups: comp.lang.lisp
- Subject: Re: a problem with reading a stream
- Message-ID: <1993Jan6.013014.7927@pentagon-gw.army.mil>
- Date: 6 Jan 93 01:30:14 GMT
- References: <1992Dec27.014528.17943@news.columbia.edu>
- Organization: U.S. Army Artificial Intelligence Center, The Pentagon
- Lines: 40
-
- In article <1992Dec27.014528.17943@news.columbia.edu> rs69@cunixb.cc.columbia.edu (Rong Shen) writes:
- >Hi experts:
- >
- > I am trying to write a function that asks a path to a file
- >from the user and opens the file to read. There is no problem with
- >opening the file, but when it tries to read, the interpreter
- >complains.
- >
- > Can anyone tell me why?
- >
- > Thanks very much.
- >
- >--
- >rs69@cunixb.cc.columbia.edu
- >
- >(defun read-path ()
- > (format t "Enter the path to the file to read, e.g. /tmp/foo/faq.txt")
- > (setf file-path-name (read-line))
- > (setf what-stream (open file-path-name :direction :input)) ; ok
- >
- > (read what-stream nil 'This-is-the-end-of-the-world)) ; This line has error;
-
- 1. What is the error? A trip into the debugger? Returns 'THIS-IS-THE...?
-
- 2. What's in the file you're trying to read?
-
- 3. Suggestion: Although (open ..) works, you should use WITH-OPEN-FILE
- e.g.,
- (with-open-file (input file-path-name)
- (loop as line = (read-line input nil nil)
- while line
- do
- (....)))
-
- If you use (OPEN ..), then error off, the stream is left open and can
- prevent you from further attempts to read the file until you explicitly
- close it. On some machine this can be less than straightforward. On
- Symbolics you can use (FS:CLOSE-ALL-FILES).
-
- Pete.
-