Subject: Re: open and :supersede
From: rpw3@rpw3.org (Rob Warnock)
Date: Sun, 12 Apr 2009 19:22:24 -0500
Newsgroups: comp.lang.lisp
Message-ID: <JtCdnRvNroVdGH_UnZ2dnUVZ_rudnZ2d@speakeasy.net>
Pascal J. Bourguignon <pjb@informatimago.com> wrote:
+---------------
| Spiros Bousbouras <spibou@gmail.com> writes:
| > I was thinking perhaps a situation where you want to
| > modify a file in place. So you do
| > (open filespec :direction :input) and then
| > (open filespec :direction :output :if-exists :supersede)
| > You read from the first stream , do the modifications you want
| > and write to the second stream. When you're finished you close
| > the first stream and then the second. Would this work ?
| 
| You cannot open the same file twice at the same time.  
+---------------

I can't find any restriction against this in the CLHS "Function OPEN"
page. And, indeed, neither CMUCL nor CLISP seems to complain:

    cmu> (with-open-file (s0 "foo1")
      (with-open-file (s1 "foo1")
	(with-open-file (s2 "foo1")
	  (mapcar #'read-line (list s0 s1 s2)))))

    ("Hello, there!" "Hello, there!" "Hello, there!")
    cmu> 

    [1]> (with-open-file (s0 "foo1")
      (with-open-file (s1 "foo1")
	(with-open-file (s2 "foo1")
	  (mapcar #'read-line (list s0 s1 s2)))))
    ("Hello, there!" "Hello, there!" "Hello, there!")
    [2]> 


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607