Newsgroups: comp.lang.lisp
From: cbbro...@news.hex.net (Christopher Browne)
Date: 2000/06/23
Subject: Re: Newbie asking for help
Centuries ago, Nostradamus foresaw a time when The Glauber would say:
>In article <8iti9v$d1...@nnrp1.deja.com>, glauber wrote: #<END-OF-FILE> may be "pretty cool," but certainly isn't conformant >[...] >> ;; 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)))) >> It doesn't work (it just hangs, so i think it's stuck in the loop). I >OK. Using TRACE, i found that read-line wasn't returning nil, but with the standard. >;; count lines I somewhat like the following: >(with-open-file (ifile "key.html" :direction :input) > (setf nlines 0) > (loop > (if (eql 'eof (read-line ifile nil 'eof)) > (return (print nlines)) > (setf nlines (+ 1 nlines))))) >And it works... >And, of course, this works too: >(with-open-file (ifile "key.html" :direction :input) >So, i plod along, undaunted... (with-open-file (ifile "c:/home/html/lynx-boo.htm" :direction :input) (loop for line = (read-line ifile nil 'eof) for lines = 0 then (+ lines 1) ;;; Line count... until (eql line 'eof) finally (return lines))) The use of "for" clauses has the merit of eliminating the extra You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||