Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Newbie asking for help
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Lieven Marchand  
View profile  
 More options Jun 22 2000, 3:00 am
Newsgroups: comp.lang.lisp
From: Lieven Marchand <m...@bewoner.dma.be>
Date: 2000/06/22
Subject: Re: Newbie asking for help

The Glauber <theglau...@my-deja.com> writes:
> And, of course, this works too:

> (with-open-file (ifile "key.html" :direction :input)
>                 (setf nlines 0)
>                 (loop
>                   (if (read-line ifile nil nil)
>                     (setf nlines (+ 1 nlines))
>                     (return (print nlines)))))

> So, i plod along, undaunted...
> I'm pretty sure this is an ugly program, and i appreciate suggestions.

This isn't meant to reopen the great LOOP flame war but one way of
doing it is:

(with-open-file (ifile "key.html" :direction :input)
  (loop for line = (read-line ifile nil)
        while line
        counting 1))

If the loop implementation of your CL system supports extending loop
paths you can even write a loop path that gives you each line in the
file. I have such a thing in my .clinit.

Then you can do:

(loop for line being each line of ifile
      count 1)

If you use the simple loop, you might consider do:

(with-open-file (ifile "/etc/passwd" :direction :input)
  (do ((line (read-line ifile nil) (read-line ifile nil))
       (count 0))
      ((null line) count)
    (incf count)))

--
Lieven Marchand <m...@bewoner.dma.be>
When C++ is your hammer, everything looks like a thumb.      Steven M. Haflich


 
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.