gap-packages / io

GAP package IO to do input and output
https://gap-packages.github.io/io/
Other
14 stars 14 forks source link

Properly recognise ~ in filename strings #37

Closed james-d-mitchell closed 8 years ago

james-d-mitchell commented 8 years ago

Currently on a Mac using ~ (for user directory) in the name of a file for IO_File and chums, results in fail being returned. It would be wonderful if this worked.

gap>  file := IO_File("~/tmp.txt", "w");
fail
gap>
ChrisJefferson commented 8 years ago

This is inherited from the underlying C functions -- fopen and friends don't extend filenames.

There is a function in GAP to extend home directories (USER_HOME_EXPAND), if we wanted to support this (and I personally think we should), we could consistently use that function everywhere.

james-d-mitchell commented 8 years ago

So, we would add USER_HOME_EXPAND to the GAP-level functions IO_Whatever? This would be super useful.

neunhoef commented 8 years ago

It must still be possible to access files that actually start with a ~. In shell you can use quotes. With IO_File not.

ChrisJefferson commented 8 years ago

./~... would work, or we could document globally in GAP a method of turning off ~ expansion.

neunhoef commented 8 years ago

./~... makes sense. Must be documented.

neunhoef commented 8 years ago

More global switches in a multi-threaded application is not good.

fingolfin commented 8 years ago

I am very reluctant to change this, or to accept PR #38. To me, io is a low-level wrapper library around POSIX APIs. No frills added. Its simplicity is a defining feature -- while at times this is slightly inconvenient, it also ensures there are no nasty surprises.

If you want tilde expansion, how about changing file := IO_File("~/tmp.txt", "w"); to file := IO_File(UserHomeExpand("~/tmp.txt"), "w"); ?

james-d-mitchell commented 8 years ago

The reason for introducing this was to make IO a bit more user friendly, but I'll close it now, and use UserHomeExpand in the code that I have using IO_File etc.