Boolean open modes for `open()`

I’m trying to understand the keyword arguments write, truncate, . . . , of the open() function. I put a link to the documentation at the end of this message.

Specifically, I want to know

  1. What it means if you specify write=true alone. Does it imply truncate?

  2. What happens if I specify both write=true and truncate=false without specifying append or with append=false?

It turns out that you need to solve some “equations” to find out the default values of the five boolean keywords. :slight_smile:

Does the manual actually pose a mathematical question for the reader to solve?

"Solve the following coupled set of equations:

read == !write,
write == truncate | append,
truncate == !read & write,

where append == false". Then what is the value of create as defined by

create == !read & write | truncate | append

?

Actually, I’ve now solve the coupled equations in my head and I think the answer is write == truncate == !read and the solution isn’t unique: there are two solutions: (write, truncate, read) == (true, true, false) or (false, false, true).

Therefore, when append == false (default value), write==true does imply truncate==true. That’s the answer to question 1 above.

I still don’t know the answer to question 2 above. Would it be overwriting the existing file from the top? (Here I’m remembering Fortran’s position="rewind".)

https://docs.julialang.org/en/v1/base/io-network/

This is my interpretation of the manual (I have not tested it):

  1. write=true implies read==false implies truncate==true
  2. write=true && truncate=true still implies append==false, so I would expect that it does a partial overwrite (unless you write more bytes than the size of the existing file) starting at the beginning.

julia/base/io.jl at 7c9a4658bcb39329a80279e8456bbac58ec9e94f · JuliaLang/julia · GitHub is the actual code that sorts out the default values. But yeah, the docs are ambiguous about what happens if you just set append=false.