Hi again, and thank you very much for your answers.
What I'm attempting to do is:
+ I've got a file ("input.txt")
-------//-----------
1.John;Engineer
2.Anthony;Chief
3.Susanne;Secretary
4.Richard;Engineer
-------//---------
+ I want to read this file ("input.txt"), and I want to select only
the characters between "." and ";", creating a list.
I mean, from "input.txt", I want to obtain:
"John" "Anthony" "Susanne" "Richard"
But I'm not able to carry it out. I would be extremely obliged if
anybody could provide me any help.
Wishes.
···@bilbao.com (Cad Bilbao) writes:
> Hi again, and thank you very much for your answers.
>
> What I'm attempting to do is:
>
> + I've got a file ("input.txt")
> -------//-----------
> 1.John;Engineer
> 2.Anthony;Chief
> 3.Susanne;Secretary
> 4.Richard;Engineer
> -------//---------
> + I want to read this file ("input.txt"), and I want to select only
> the characters between "." and ";", creating a list.
>
> I mean, from "input.txt", I want to obtain:
> "John" "Anthony" "Susanne" "Richard"
>
> But I'm not able to carry it out. I would be extremely obliged if
> anybody could provide me any help.
Is this homework?
Where I'd start would be something like:
(format t "~A~% " (let ((r nil))
(with-open-file
(s "home:input.txt" :direction :input)
(setf r
(loop
for line = (read-line s nil nil)
while line
collect (subseq line (search "." line) (search ";" line)))))
r))
It's got errors, and there are some bits that are definitely a bit
odd. I'd not claim it to be an ideal implementation by _any_ means.
But it produces meaningful output that's not _spectacularly_ different
from what you were looking for, and hopefully provides at least food
for thought.
--
(concatenate 'string "cbbrowne" ·@cbbrowne.com")
http://www.cbbrowne.com/info/xwindows.html
Q: Why did they deprecate a.out support in linux?
A: Because a nasty coff is bad for your elf. --- James Simmons
Hi and than you very much for answering.
I'll try it.
········@acm.org wrote in message news:<·······················@news20.bellglobal.com>...
> ···@bilbao.com (Cad Bilbao) writes:
> > Hi again, and thank you very much for your answers.
> >
> > What I'm attempting to do is:
> >
> > + I've got a file ("input.txt")
> > -------//-----------
> > 1.John;Engineer
> > 2.Anthony;Chief
> > 3.Susanne;Secretary
> > 4.Richard;Engineer
> > -------//---------
> > + I want to read this file ("input.txt"), and I want to select only
> > the characters between "." and ";", creating a list.
> >
> > I mean, from "input.txt", I want to obtain:
> > "John" "Anthony" "Susanne" "Richard"
> >
> > But I'm not able to carry it out. I would be extremely obliged if
> > anybody could provide me any help.
>
> Is this homework?
>
> Where I'd start would be something like:
>
> (format t "~A~% " (let ((r nil))
> (with-open-file
> (s "home:input.txt" :direction :input)
> (setf r
> (loop
> for line = (read-line s nil nil)
> while line
> collect (subseq line (search "." line) (search ";" line)))))
> r))
>
> It's got errors, and there are some bits that are definitely a bit
> odd. I'd not claim it to be an ideal implementation by _any_ means.
>
> But it produces meaningful output that's not _spectacularly_ different
> from what you were looking for, and hopefully provides at least food
> for thought.
From: JP Massar
Subject: Re: What I'm trying to do (reading a file)
Date:
Message-ID: <3bfe9453.220116124@news>
On 23 Nov 2001 08:29:51 -0800, ···@bilbao.com (Cad Bilbao) wrote:
>Hi again, and thank you very much for your answers.
>
>What I'm attempting to do is:
>
>+ I've got a file ("input.txt")
>-------//-----------
>1.John;Engineer
>2.Anthony;Chief
>3.Susanne;Secretary
>4.Richard;Engineer
>-------//---------
>+ I want to read this file ("input.txt"), and I want to select only
>the characters between "." and ";", creating a list.
>
>I mean, from "input.txt", I want to obtain:
>"John" "Anthony" "Susanne" "Richard"
>
>But I'm not able to carry it out. I would be extremely obliged if
>anybody could provide me any help.
>
Assume you already have a line in the form of a string from your input
file.
Write a function which extracts the characters between '.' and ';'
from that string.
See POSITION and SUBSEQ in your Common Lisp book or online reference.
Think about whether you want to handle the cases where there is no
'.', no ';' or the ';' occurs before the '.'.
Now write some code that reads successive lines from a file.
See WITH-0PEN-FILE and READ-LINE.
Now put the two together, with a mechanism to store the results of
your processing of each line in a list. See LET, PUSH, REVERSE and
NREVERSE.