From: Olmeda Piero
Subject: help for "read from file" and "write to file"
Date:
Message-ID: <356B2321.2833@worldonline.nl>
I am trying to write a procedure for reading words from an ascii file on
the hard disk (eliminating all the punctuaction, that is !;,:, etc) and
putting them in a list that is a value of a global variable.
I am using Allegro Common Lisp version 3.02 lite.
The original version of the procedure (some years ago...) in Cambridge
Lisp was something like this:
(de make!-cleaned!-list (infile)
(prog (oldin s listfile)
(setq oldin (rds (open infile 'input)))
loop
(setq s (readch))
(cond
((eq s !$eof!$)
(go end))
((and (nomember s '(!! !" !( !) !- !` !: !; !' !, !. !?))
(neq s blank)
(neq s !$eol!$))
(setq listfile (cons s listfile))
(go loop))
(t (go loop)))
end
(rds oldin)
(close infile)
(return (reverse listfile))))
I have some difficulties in the translation to Common Lisp.
I have the same problem for writing the value of a global variable to a
file.
Really I have this general problem also: How can I save to a file the
value of ALL my global variables at the end of my lisp session?
Thank You very much.
Piero Olmeda
--
E-MAIL ······@worldonline.nl
In article <·············@worldonline.nl>,
Olmeda Piero <······@worldonline.nl> wrote:
>I am trying to write a procedure for reading words from an ascii file on
>the hard disk (eliminating all the punctuaction, that is !;,:, etc) and
>putting them in a list that is a value of a global variable.
>I am using Allegro Common Lisp version 3.02 lite.
>The original version of the procedure (some years ago...) in Cambridge
>Lisp was something like this:
>
>(de make!-cleaned!-list (infile)
> (prog (oldin s listfile)
> (setq oldin (rds (open infile 'input)))
> loop
> (setq s (readch))
> (cond
> ((eq s !$eof!$)
> (go end))
> ((and (nomember s '(!! !" !( !) !- !` !: !; !' !, !. !?))
> (neq s blank)
> (neq s !$eol!$))
> (setq listfile (cons s listfile))
> (go loop))
> (t (go loop)))
> end
> (rds oldin)
> (close infile)
> (return (reverse listfile))))
I don't know what "rds" does, but the following probably does what that
above procedure does.
(defun make-cleaned-list (infile)
(with-open-file (oldin infile :direction :input)
(loop for s = (read-char infile nil 'eof)
until (eq s 'eof)
when (alphanumericp s) collect s)))
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
From: Olmeda Piero
Subject: Re: help for "read from file" and "write to file"
Date:
Message-ID: <356D6A14.258C@worldonline.nl>
> I don't know what "rds" does, but the following probably does what that
> above procedure does.
>
> (defun make-cleaned-list (infile)
> (with-open-file (oldin infile :direction :input)
> (loop for s = (read-char infile nil 'eof)
> until (eq s 'eof)
> when (alphanumericp s) collect s)))
>
> --
> Barry Margolin, ······@bbnplanet.com
> GTE Internetworking, Powered by BBN, Cambridge, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Thank You for the suggestion!
--
E-MAIL ······@worldonline.nl