Beginners Problem reading from two files simultaneously

Discussion of Common Lisp

Beginners Problem reading from two files simultaneously

Postby dhak6153 » Thu Jan 14, 2010 12:35 pm

Hi:

I am a beginner and I am having trouble reading from two files simultaneously. I am trying to use the with-open-file macro to get the job done. Help appreciated
dhak6153
 
Posts: 4
Joined: Thu Jan 14, 2010 12:29 pm

Re: Beginners Problem reading from two files simultaneously

Postby dhak6153 » Thu Jan 14, 2010 1:06 pm

Here is my function that works for a single file.

(defun flist (s)
(with-open-file (input s)
(loop for line = (read-line input nil nil)
while line
collect line into lines
finally (return (values lines)))))
dhak6153
 
Posts: 4
Joined: Thu Jan 14, 2010 12:29 pm

Re: Beginners Problem reading from two files simultaneously

Postby Ramarren » Thu Jan 14, 2010 1:57 pm

I don't understand what your problem is. You can just open two files at the same time by nesting the WITH-OPEN-FILE macro.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: Beginners Problem reading from two files simultaneously

Postby dhak6153 » Thu Jan 14, 2010 2:05 pm

Ramarren wrote:I don't understand what your problem is. You can just open two files at the same time by nesting the WITH-OPEN-FILE macro.


The main issue that I have is I am trying to read from two different files, merge the contents and display the output. The function posted above helps me read from a file and display but I was wondering how could I use the same snippet (with some modification??) to get the job done.

Thank you.
dhak6153
 
Posts: 4
Joined: Thu Jan 14, 2010 12:29 pm

Re: Beginners Problem reading from two files simultaneously

Postby Ramarren » Thu Jan 14, 2010 2:23 pm

Are you beginner to Lisp or to programming in general? You did not write what is exactly stopping you from implementing what you want. If you do not understand the snippet you posted sufficiently to make the modifications I would suggest reading either Common Lisp: A Gentle Introduction to Symbolic Computation by David S. Touretzky or Practical Common Lisp, both of which will teach you more than what can be explained in a forum post at this level.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: Beginners Problem reading from two files simultaneously

Postby dhak6153 » Thu Jan 14, 2010 2:38 pm

Awesome!!! Thanks a lot for pointing me towards those invaluable online resources. Now I can teach myself and get into a proficiency level that I need.

Thank you.
dhak6153
 
Posts: 4
Joined: Thu Jan 14, 2010 12:29 pm


Return to Common Lisp

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests

cron