Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open files in append mode #7

Open
tizoc opened this issue Oct 10, 2016 · 4 comments
Open

Open files in append mode #7

tizoc opened this issue Oct 10, 2016 · 4 comments

Comments

@tizoc
Copy link
Member

tizoc commented Oct 10, 2016

Append mode streams discussion

Shen truncates files when it opens them and there is no way to specify if files should be opened in stream mode.

Current implementations

TODO: add others

@rkoeninger
Copy link
Member

rkoeninger commented Jan 30, 2017

I think the most consistent way to add this would be to have (open FilePath append) and avoid adding a new function.

I added it this way in my port: rkoeninger/ShenSharp@620c042

@tizoc
Copy link
Member Author

tizoc commented Jan 31, 2017

@rkoeninger have you tried it with the type checker enabled? because adding support in the backend is not enough since Shen's type-checker treats open in a special way (it recognizes uses of open, takes the last argument and then uses it to construct the type of the resulting value).

In your case, when you open with append you will get a result with type (stream append) which is incompatible with (stream out).

@tizoc
Copy link
Member Author

tizoc commented Jan 31, 2017

To clarify, it is not something that is not fixeable, I know what code to change and where, but I would rather not introduce changes to existing functionality when possible.

Also I never really liked for open to work the way it works, I would rather have two separate functions, open-in and open-out, it is simpler that way, doesn't require anything special from the typechecked, and an extra parameter could be used to pass extra options, something like this for append for example:

(open-out "/some/path" [append create-if-not-exists])
(open-out "/some/path" [truncate])
(open-out "/some/path" [fail-if-exists])

etc etc (you get the idea).

This option leaves things open for further extension (because append is not the only possible modifier for how files are opened).

@rkoeninger
Copy link
Member

I get a type error for (open "file.txt" append), but you're right - the open function is weird.

I'm guessing the additional options would all optional per platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants