Arc Forumnew | comments | leaders | submitlogin
1 point by Pauan 4618 days ago | link | parent

As akkartik said, the problem is that "write" wraps strings in double-quotes. Oddly enough, Arc doesn't provide dispfile, which would do what you want. There's two ways to implement dispfile: the simple way...

  (def dispfile (val file)
    (w/outfile f file
      (disp val f))
    val)
...or by copy+pasting writefile and changing it to use disp:

  (def dispfile (val file)
    (let tmpfile (+ file ".tmp")
      (w/outfile o tmpfile (disp val o))
      (mvfile tmpfile file))
    val)
I personally would go for the simple way. I dislike the way Arc handles temporary files, so if I wanted to use temp files + move, I'd end up changing the entire temporary file implementation...


3 points by akkartik 4617 days ago | link

For comparison, I think this is the shortest way to do this without introducing a new name:

  (tofile "tmpfile" (disp "this is some text"))
---

How would you better implement writefile? I think the goal is to avoid corrupting a file that gets repeatedly updated. If the disk fills up, for example, you might end up losing the previous version and unable to fully write the new version.

-----

1 point by zck 4617 days ago | link

What don't you like about the way Arc handles temporary files? Is that you can't have another file named that? Arc could use `(file-gensym)` instead, if that was a thing.

-----

2 points by Pauan 4611 days ago | link

To put it simply, I think Arc should use Racket's support for temporary files:

http://docs.racket-lang.org/reference/Filesystem.html?q=temp...

-----

1 point by akkartik 4610 days ago | link

Ok, done: http://github.com/nex3/arc/commit/df9fd21eeb

Thanks for the tip! I had no idea there could be a better way. Now I find that my use of $RANDOM in shell scripts should be replaced with calls to mktemp as well.

-----

1 point by akkartik 4616 days ago | link

Ah, good point. Here's a quick-and-dirty fix:

http://github.com/nex3/arc/commit/c70a51a4d5

Now tofile does the 'write to tmp file and move' dance. writefile is implemented in terms of tofile. Finally, the tmp file is more randomly chosen, so it should be thread-safe.

-----