From ... From: Erik Naggum Subject: Re: Newbie asking for help Date: 2000/06/22 Message-ID: <3170687446231361@naggum.no>#1/1 X-Deja-AN: 637747619 References: <8iti9v$d19$1@nnrp1.deja.com> mail-copies-to: never Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 961701490 14805 195.0.192.66 (22 Jun 2000 19:18:10 GMT) Organization: Naggum Software; vox: +47 8800 8879; fax: +47 8800 8601; http://www.naggum.no User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.6 Mime-Version: 1.0 NNTP-Posting-Date: 22 Jun 2000 19:18:10 GMT Newsgroups: comp.lang.lisp * The Glauber | I'm having trouble going from the tutorials to the real world. For | example, a lot of what i do is related to processing text files. | So, i though i'd write a simple/stupid program to count the number | of lines in a file. Here it is: | | ;; count number of lines in file key.html | (with-open-file (ifile "key.html" :direction :input) | (setf nlines 0) | (loop | (if (read-line ifile nil) | (setf nlines (+ 1 nlines)) | (return nlines)))) You're using a free variable, nlines, in this code. You should not use a free variable unless you have very specific need for it. This does not affect the correctness of your code, however. | It doesn't work (it just hangs, so i think it's stuck in the loop). Try being explicit in the value of eof-value, i.e. (read-line ifile nil nil) | I thought it would read lines until the end of the file, when the | read- line would return nil, and that would trigger the second form | inside the if (a return, to get out of the loop). I think it would be instructive to print the value from read-line: (print (read-line ifile nil)) print returns its value. | I'm sorry for posting something so stupid, but why doesn't this work? Seems like a bug in your Common Lisp implementation. Which is it? #:Erik -- If this is not what you expected, please alter your expectations.