home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / lisp / 3205 < prev    next >
Encoding:
Text File  |  1993-01-08  |  1.7 KB  |  51 lines

  1. Path: sparky!uunet!dtix!mimsy!prometheus!media!hqda-ai!grant
  2. From: grant@pentagon-gw.army.mil (Pete Grant)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: a problem with reading a stream
  5. Message-ID: <1993Jan6.013014.7927@pentagon-gw.army.mil>
  6. Date: 6 Jan 93 01:30:14 GMT
  7. References: <1992Dec27.014528.17943@news.columbia.edu>
  8. Organization: U.S. Army Artificial Intelligence Center, The Pentagon
  9. Lines: 40
  10.  
  11. In article <1992Dec27.014528.17943@news.columbia.edu> rs69@cunixb.cc.columbia.edu (Rong Shen) writes:
  12. >Hi experts:
  13. >
  14. >    I am trying to write a function that asks a path to a file
  15. >from the user and opens the file to read. There is no problem with
  16. >opening the file, but when it tries to read, the interpreter
  17. >complains.
  18. >
  19. >    Can anyone tell me why?
  20. >
  21. >    Thanks very much.
  22. >
  23. >--
  24. >rs69@cunixb.cc.columbia.edu
  25. >
  26. >(defun read-path ()
  27. >  (format t "Enter the path to the file to read, e.g. /tmp/foo/faq.txt")
  28. >  (setf file-path-name (read-line))
  29. >  (setf what-stream (open file-path-name :direction :input)) ; ok
  30. >
  31. >  (read what-stream nil 'This-is-the-end-of-the-world)) ; This line has error;
  32.  
  33. 1.  What is the error?  A trip into the debugger?  Returns 'THIS-IS-THE...?
  34.  
  35. 2.  What's in the file you're trying to read?
  36.  
  37. 3.  Suggestion:  Although (open ..) works, you should use WITH-OPEN-FILE
  38.     e.g.,
  39.     (with-open-file (input file-path-name)
  40.       (loop as line = (read-line input nil nil)
  41.             while line
  42.             do
  43.         (....)))
  44.  
  45.   If you use (OPEN ..), then error off, the stream is left open and can
  46. prevent you from further attempts to read the file until you explicitly
  47. close it.  On some machine this can be less than straightforward.  On
  48. Symbolics you can use (FS:CLOSE-ALL-FILES).
  49.  
  50. Pete.
  51.