[racket] Looking for guidelines regarding paths...

From: Danny Yoo (dyoo at hashcollision.org)
Date: Mon May 14 11:56:47 EDT 2012

> I suspect that "path" abstraction was created a means for manipulating file
> pathnames in a way that is cross-platform and also less prone to error than
> using strings.

That's the impression I get from this section in the reference:


That being said, I think the Guide should have something to say on
this matter.  I remember being a bit confused too as to why there's a
separate datatype for paths.

When I was learning Racket, I did not realize immediately that there's
a distinction between doing something like this:

   (build-path "foo/bar.rkt")


  (build-path "foo" "bar.rkt")

There some be some advisory that recommends the second in favor of the
first: it's not immediately obvious why the second is better.  The
main reason is that the second is more platform agnostic: Windows does
not use "/" as a path separator, and the path-manipulating functions
use the conventions of the native platform.  So, for example, on my
Windows system, these two paths are not equal?

> (equal? (build-path "foo/bar.rkt") (build-path "foo" "bar.rkt"))

The version that uses build-path in a platform-agnostic way uses the
Windows platform convensions, so it uses the backslash to separate
path elements:

;; On a Windows environment:
> (path->string (build-path "foo" "baz" "bar.rkt"))

And if we were to run this on a Unix environment, we'd see forward
slashes instead.  So the separate path datatype is meant to insulate
against platform conventions.

Posted on the users mailing list.