Hi Matthew, Thanks for clarifying this.
It seems to me that `build-path/convention-type` is very difficult to use correctly: it is very easy for someone working on a Linux machine to just use this function with a 'unix convention and plain strings, under the assumption that it will work correctly on a Windows machine. The documentation for the function seem imply that it is this easy, but it is not. Even the return value for the function seems to be a "unix-path" if I run it with a 'unix convention, but a "path" if I run it with a 'windows convention, so `path->string` will not always work on the return type. Even when it fails, the error message is confusing, as "foo" is in fact a valid "path element" : > (build-path/convention-type 'unix "foo" "bar") build-path/convention-type: specified convention incompatible with string path element path element: "foo" convention: 'unix I would suggest that the documentation for this function is updated to at least mention this caveat. I'm not sure how the error message could be improved, but it is confusing as it is. For me, the following wrapper function seems to work OK: (define (build-path/ct type base . sub) (define b-base (string->bytes/utf-8 base)) (define b-sub (map string->bytes/utf-8 sub)) (define result (apply build-path/convention-type type (bytes->path b-base type) (map (lambda (b) (bytes->path b type)) b-sub))) (bytes->string/utf-8 (path->bytes result))) BTW, I found this problem, when working on the "frog" blog generator: its unit tests fail on windows because it generates windows style paths and compares them to unix style path strings and it also generates the internal links for the HTML pages using the Windows convention. Best regards, Alex, On Tuesday, May 22, 2018 at 7:56:21 PM UTC+8, Matthew Flatt wrote: > > To build paths for a convention other than the current machine's > convention, you have to work in bytes instead of strings. > > (define (bs->p bs) (bytes->path bs 'unix)) > (build-path/convention-type 'unix (bs->p #"/") (bs->p #"foo") (bs->p > #"bar")) > > Roughly, strings don't work, because they have to be converted to bytes > using the locale's default encoding. Although strings are allowed for > the current platform's convention on the assumption that the current > locale's encoding is the right one, we've avoided building in any > assumption about the encoding for the other convention. > > At Tue, 22 May 2018 03:51:03 -0700 (PDT), Alex Harsanyi wrote: > > I am trying to create a path named "/foo/bar" in Racket on a windows > > machine. build-path produces "/foo\\bar" and build-path/convention-type > > does not seem to work: > > > > > (path->string (build-path "/" "foo" "bar")) > > "/foo\\bar" ; I am running on a Windows machine, so this is expected > > > (path->string (build-path/convention-type 'windows "/" "foo" > "bar")) > > "/foo\\bar" > > > (path->string (build-path/convention-type 'unix "/" "foo" "bar")) > > ; build-path/convention-type: specified convention incompatible with > > string path element > > ; path element: "/" > > ; convention: 'unix > > > (path->string (build-path/convention-type 'unix "/foo" "bar")) > > ; build-path/convention-type: specified convention incompatible with > > string path element > > ; path element: "/foo" > > ; convention: 'unix > > > > It seems that I cannot specify the root path, "/", when the convention > type > > is set to 'unix. Technically, the error is correct, as "/" is not a > valid > > directory name, but I am not sure what to replace it with. The empty > string > > does not work either. The unix convention type seems to be more strict > > than the windows one: > > > > > (path->string (build-path/convention-type 'windows "./foo/" > "bar")) > > "./foo/bar" > > > (path->string (build-path/convention-type 'unix "./foo/" "bar")) > > ; build-path/convention-type: specified convention incompatible with > > string path element > > ; path element: "./foo/" > > ; convention: 'unix > > > > Is this a bug, or I am missing something? > > > > Alex. > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "Racket Users" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to racket-users...@googlegroups.com <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.