[racket] open-output-file #:exist

From: Hendrik Boom (hendrik at topoi.pooq.com)
Date: Wed Aug 24 13:36:40 EDT 2011

There was once work on an ISO standard for a "Software Bus", a set of 
relatively low-level primitive operations that would do just about 
everything you'd need to talk to an OS and which could be easily 
implemented with a lightweight software layer on just about any OS.  It 
was torpedooed by the American representatives on the committee (who 
wanted nothing to compete with the Unix API).

I got to look at a draft once, and it looked like a good design.

One thing in particular I noticed was that it separated a files
identity from both its name and its content.  You could take a file name 
and use it to get some kindd of identity token, which could sobsequently 
be used to create it, destroy it, open it, close it, lock it, and so 
forth.  In particular, it wasn't necessary for the file to actually 
exist for it to be locked against acess by others.

That seemed like a useful concept.

-- hendrik

On Wed, Aug 24, 2011 at 09:51:54AM -0600, Matthew Flatt wrote:
> Does anyone know a good reference to cite for this information? Like
> the details of TCP, I think this is something better explained by an
> external reference than in the Racket reference manual.
> 
> Meanwhile, I'll look into smoothing the path from functions like
> `with-output-to-file' to information about the `exists' values.
> 
> At Wed, 24 Aug 2011 17:23:52 +0200, Stephan Houben wrote:
> > Hi Marijn,
> > 
> > At least on Unix/Linux, a file (inode) has some distinct identity
> > apart from its content.
> > 
> > If a file is truncated, this is observed by all processes which have the file
> > open. In addition, all hard-links to the file are also truncated (since
> > these are just references to the same inode).
> > 
> > If a file is replaced, the old inode is unaffected: processes which
> > had the file open continue to see the old data, other hard links
> > keep referring to the old file.
> > 
> > If you don't care about these subtleties you can use truncate/replace.
> > 
> > must-truncate is, I think, mostly useful if the file is to be used
> > for some form of inter-process communication. must-replace doesn't seem
> > useful in any way to me and moreover cannot be implemented reliably
> > without introducing a race condition between checking for existence of
> > the file and overwriting it with a new one.
> > 
> > Stephan
> > 
> > On 08/24/2011 03:01 PM, Marijn wrote:
> > > -----BEGIN PGP SIGNED MESSAGE-----
> > > Hash: SHA1
> > >
> > > Hi,
> > >
> > > In the reference in section 12.1.5 File Ports[1], open-output-file is
> > > defined as having an optional keyword argument #:exist which can have
> > > one of 8 different values. The same options are used for a number of
> > > wrapper functions, among which with-output-to-file[2].
> > > If you go to [2] you need to follow 3 internal links to similar
> > > functions to get to open-output-file[1] to find out what the different
> > > values of the #:exists argument mean. I think it would be good if a link
> > > was inserted such that you can go straight there.
> > > Unfortunately I find some of the explanations not so clear. I will
> > > comment on the explanation of each option in the order they appear in
> > > the docs.
> > > 1) error: this one is clear
> > > 2) replace: how is this different from 3) truncate?
> > > 3) truncate: see 2)
> > > 4) must-truncate: what about must-replace?
> > > 5) truncate/replace: clear if 2) and 3) are clarified
> > > 6) update: what is the current read/write position (this is hinted at in
> > > 8), but should really be explained fully here) and what happens when you
> > > write to the file (does it overwrite, insert, either depending on some
> > > other option)?
> > > 7) can-update: clear if 6) clarified
> > > 8) append: why is it only equivalent to update on Windows?
> > >
> > > Marijn
> > >
> > >
> > > 
> > [1]:http://docs.racket-lang.org/reference/file-ports.html?#%28def._%28%28lib._ra
> > cket/private/base..rkt%29._open-output-file%29%29
> > > 
> > [2]:http://docs.racket-lang.org/reference/file-ports.html?#%28def._%28%28lib._ra
> > cket/private/base..rkt%29._with-output-to-file%29%29
> > > -----BEGIN PGP SIGNATURE-----
> > > Version: GnuPG v2.0.17 (GNU/Linux)
> > > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> > >
> > > iEYEARECAAYFAk5U9jIACgkQp/VmCx0OL2wy8ACbBPOVfHYF53NTCkY/9qXnbeyP
> > > AIAAn3J0URrJsIIZZiVIh/EOGqOBBJrX
> > > =rLk7
> > > -----END PGP SIGNATURE-----
> > > _________________________________________________
> > >    For list-related administrative tasks:
> > >    http://lists.racket-lang.org/listinfo/users
> > >
> > _________________________________________________
> >   For list-related administrative tasks:
> >   http://lists.racket-lang.org/listinfo/users
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.