William James
6/8/2015 5:37:00 PM
cbbrowne wrote:
> > + 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.
Gauche Scheme:
(with-input-from-file "junk"
(lambda ()
(generator-map
(compose (cut <> 1) #/[.](.*?);/)
read-line)))
===>
("John" "Anthony" "Susanne" "Richard")
Another way:
(with-input-from-file "junk"
(lambda ()
(generator-map
(compose cadr (cut string-split <> #[.;]))
read-line)))
Another way:
(with-input-from-file "junk"
(lambda ()
(generator-map
(compose (cut string-scan <> #\; 'before)
(cut string-scan <> #\. 'after))
read-line)))
--
Swedes are now in many ways treated as second-class citizens in their own
country. The very word "Swede" has been given a negative connotation. This kind
of project has now been introduced all over Western Europe.
fjordman.blogspot.ca/2005/05/is-swedish-democracy-collapsing.html