Closed zck closed 3 years ago
+1, looks good. Is this a purely aesthetic choice or did you see this changing behavior somewhere?
I haven't tested it on Windows but it should be fine based on the Racket docs. (search for "cleanse")
It's just an aesthetic choice, one to work better with the general expectations of the underlying OS.
Basically when I use Anarki and want to open a file, I always forget ~/
doesn't work. So now it does.
Oh so it doesn't actually work? 👍
Haha, it did not work before this PR, no. Previously, you'd see something like this:
arc> (outfile "~/test.txt")
open-output-file: error opening file
path: /home/zck/programs/arc/anarki/~/test.txt
system error: No such file or directory; errno=2
context...:
body of "/home/zck/programs/arc/anarki/ac.rkt"
/home/zck/programs/arc/anarki/ac.rkt:1456:4
With this PR:
arc> (outfile "~/test.txt")
#<output-port:/home/zck/test.txt>
We use the racket function expand-user-path to expand ~/ to the user's home directory. We call this function for both infiles and outfiles.
This can be tested with
(outfile "~/test.txt")
. You should see something like this:#<output-port:/home/zck/test.txt>
Infiles only work if the file exists. Here's a way to print out all lines of a file:
Obviously, both fully qualified names and relative names should continue to work:
I'd like to have this tested on Windows; I've tested it on Linux.
Also, I'd be interested to see if this can be unit tested. I'm not especially sure how to at the moment.