Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
simple lisp question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John Hunter  
View profile  
 More options Oct 24 2000, 3:00 am
Newsgroups: comp.lang.lisp
From: John Hunter <jdhun...@nitace.bsd.uchicago.edu>
Date: 2000/10/24
Subject: simple lisp question

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.

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?  

I thought this would be a relatively common thing to do and someone
might already have some template functions which I could follow.

Thanks,
John Hunter


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Margolin  
View profile  
 More options Oct 24 2000, 3:00 am
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@genuity.net>
Date: 2000/10/24
Subject: Re: simple lisp question
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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »