[plt-scheme] Explode-path and normalized file paths

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Sep 23 20:09:24 EDT 2006

At Sun, 24 Sep 2006 00:45:41 +0200, Jens Axel Søgaard wrote:
> Here is a fun error message:
> 
>   exception raised by exception handler:
>      continuation application: attempted to cross a continuation barrier;
>   original exception raised: explode-path: expects argument of type
>   <path in normal form>; given
>   #<path:c:/tmp/planet/source/cce\website.plt\current\private\require.ss>
> 
> Is it correct to assume that this means, the path
> 
>      c:/tmp/planet/source/cce\website.plt\current\private\require.ss
> 
> is normalized on Windows, but not on Linux?

Yes. It's not an absolute path on Windows.

The `explode-path' function actually needs an absolute path that has no
"." or ".." in it. I'll change the error message and the docs.

> And if so, is there another robust way to split the path?
> 
> I need it in this context:
> 
>    (define (document-number->url index d)
>      (cond
>        [(document-number->source-path index d)
>         => (lambda (full-path)
>              (apply string-append
>                     planet-url-root
>                     (intersperse "/"
>                                  (map path->string
>                                       (cddddr (explode-path
>                                                 full-path))))))]
>        [else
>         #f]))

I think you probably need `full-path' to be an absolute path for this
application. Unless you want to support "." and "..", then
`explode-path' is still probably the thing to use. But you can always
write a loop with `split-path'.

Matthew



Posted on the users mailing list.