[plt-scheme] parsing windows path on linux?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Jan 11 09:49:05 EST 2009

At Sat, 10 Jan 2009 23:15:24 -0800, YC wrote:
> On Sat, Jan 10, 2009 at 8:14 PM, Eli Barzilay <eli at barzilay.org> wrote:
> >
> > It looks like the reason for this is that a non-default-platform path
> > is not considered as a path in the `path?' sense -- so you get an
> > error.  But you can use `split-path' directly (which is what
> > `file-name-from-path' is doing):
> >
> > (let-values ([(base file dir?)
> >              (split-path (bytes->path #"c:\\foo\\bar.txt" 'windows))])
> >  file)
> >
> Thanks for the tip, Eli.
> It seems that windows-path cannot be directly manipulated except through a
> few path functions.  It took me a while to figure out how to convert
> windows-path back to string: first use path->bytes and then
> bytes->string/utf-8.
> Are there thoughts to allow all path functions to manipulate the different
> path types?  It seems the differences between these path types are not
> great.

Since most of the functions provided by `scheme/path' manipulate paths
without consulting the filesystem, I've changed them to work with paths
of any kind. (The exceptions are `normalize-path' and
`simple-form-path', which rely on the filesystem.)

I'm less certain that it would be a good idea to change `string->path'
and `path->string' to allow with paths for a different system kind. The
problem is that string<->path conversions are inherently approximate;
some paths cannot be represented as strings, and for Unix paths, the
conversion depends on a locale-specific encoding. If you're
manipulating paths for a different system and you're forced to start
and end with strings, though, then UTF-8 is probably the right choice.
So I've added `string->some-system-path' and `some-system-path->string'
to `scheme/path'.


Posted on the users mailing list.