From: Paulo J. Matos aka PDestroy
Subject: From file to list
Date: 
Message-ID: <99coi1$fc9$1@venus.telepac.pt>
Hi,
I want to take lines out of a file and put them into a list
If for example the file contains:
7 5
3 2 1 4

Then the function should return: ((7 5)(3 2 1 4))

But I'm having problems with that since it's returning nil. Something is not
quite correct:

(defun get-game-info (filename)
  (let ((file (make-pathname :name filename))
 (info-list nil))
 (with-open-file (str file :direction :input)
   (do ((line (read-line str nil 'eof)
       (read-line str nil 'eof)))
       ((eql line 'eof) (reverse info-list))
       (cons line info-list)))))


Any ideas?

Best regards,

--
Paulo J. Matos aka PDestroy
http://www.pdestroy.net
ICQ UIN - 361853

--
The hours I spend with you I look upon as sort of a perfumed garden, a dim
twilight, and a fountain singing to it, you and you alone make me feel that
I am alive. Other men it is said have seen angels, but I have seen thee and
thou art enough.
           - Moore, George

From: Barry Margolin
Subject: Re: From file to list
Date: 
Message-ID: <vNsu6.68$U4.3136@burlma1-snr2>
In article <············@venus.telepac.pt>,
Paulo J. Matos aka PDestroy <········@netcabo.pt> wrote:
>Hi,
>I want to take lines out of a file and put them into a list
>If for example the file contains:
>7 5
>3 2 1 4
>
>Then the function should return: ((7 5)(3 2 1 4))
>
>But I'm having problems with that since it's returning nil. Something is not
>quite correct:
>
>(defun get-game-info (filename)
>  (let ((file (make-pathname :name filename))
>        (info-list nil))
>    (with-open-file (str file :direction :input)
>      (do ((line (read-line str nil 'eof)
>                 (read-line str nil 'eof)))
>          ((eql line 'eof) (reverse info-list))
>        (cons line info-list)))))

The only thing you ever assign to info-list is nil; you never update it as
you go through the loop.  The last line should be:

        (setq info-list (cons line info-list))
or
        (push line info-list)

P.S. If you want help, you really should make it easier on us by indenting
your code readably, like I did.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Raymond Wiker
Subject: Re: From file to list
Date: 
Message-ID: <86n1ac3nnz.fsf@raw.grenland.fast.no>
"Paulo J. Matos aka PDestroy" <········@netcabo.pt> writes:

> Hi,
> I want to take lines out of a file and put them into a list
> If for example the file contains:
> 7 5
> 3 2 1 4
> 
> Then the function should return: ((7 5)(3 2 1 4))
> 
> But I'm having problems with that since it's returning nil. Something is not
> quite correct:
> 
> (defun get-game-info (filename)
>   (let ((file (make-pathname :name filename))
>  (info-list nil))
>  (with-open-file (str file :direction :input)
>    (do ((line (read-line str nil 'eof)
>        (read-line str nil 'eof)))
>        ((eql line 'eof) (reverse info-list))
>        (cons line info-list)))))
          ^^^^

        You're creating a cons just to throw it away. Try push
instead of cons, here.

        With this change, you should get a result of the form
("7 5" "3 2 1 4"). Thus, you also need to add code to split each line
into individual items (possibly atoms, even :-). If your data consists
of lines of integers only, you could use parse-integer in conjunction
with one of the split-string functions posted on cll sometime within
the last few weeks. Alternatively, you could simply use
read-from-string in a loop, or write your own arbitrarily complex
parser.

-- 
Raymond Wiker
·············@fast.no
From: Vladimir V. Zolotych
Subject: Re: From file to list
Date: 
Message-ID: <3ABB2C3E.B018ED4F@eurocom.od.ua>
"Paulo J. Matos aka PDestroy" wrote:
> 
> I want to take lines out of a file and put them into a list
> If for example the file contains:
> 7 5
> 3 2 1 4
> 
[snip]

>    (do ((line (read-line str nil 'eof)
>        (read-line str nil 'eof)))

You're using READ-LINE that return "7 5" "3 2 1 4"
for your file.
SPLIT function 
http://groups.google.com/groups?q=msgid:39F36F1A.B8F19D20%40simplex.nl&ic=1
and PARSE-INTEGER can help you.

-- 
Vladimir Zolotych                         ······@eurocom.od.ua