In article <1rwveyqcnd....@video.bsd.uchicago.edu>,
John Hunter <jdhun...@nitace.bsd.uchicago.edu> wrote:
>I would like a function that takes a filename as an arg and returns each line
>(separated by newline) in an alist whose car is the string of text on
>that line, and a complementary function which prints the car of the
>alist to the file.
Here's how to do it in Common Lisp.
(defun file-to-alist (filename)
(with-open-file (s filename)
(loop for line = (read-line s)
while line
collect (cons line nil))))
(defun alist-to-file (filename alist)
(with-open-file (s filename :direction :output)
(dolist (item alist)
(write-string (car item) s))))
>I have read some of the emacs lisp info manual on this subject, but
>the solution is not immediately apparent. For example, with '(read
>BUFFER)' how do
>you specify the buffer name? How do you read in a line at a time
>until the end of the file?
READ isn't used for reading lines, it's used for reading the printed
representation of a Lisp object. To get a buffer with a particular name,
use (get-buffer "name"). So to read from a specific buffer, use something
like:
(let ((buffer (get-buffer "name")))
(read buffer))
--
Barry Margolin, bar...@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.