Page 1 of 1

Beginners Problem reading from two files simultaneously

Posted: Thu Jan 14, 2010 12:35 pm
by dhak6153
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

Re: Beginners Problem reading from two files simultaneously

Posted: Thu Jan 14, 2010 1:06 pm
by dhak6153
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)))))

Re: Beginners Problem reading from two files simultaneously

Posted: Thu Jan 14, 2010 1:57 pm
by ramarren
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.

Re: Beginners Problem reading from two files simultaneously

Posted: Thu Jan 14, 2010 2:05 pm
by dhak6153
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.

Re: Beginners Problem reading from two files simultaneously

Posted: Thu Jan 14, 2010 2:23 pm
by ramarren
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.

Re: Beginners Problem reading from two files simultaneously

Posted: Thu Jan 14, 2010 2:38 pm
by dhak6153
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.