From: Kon Lovett <address@hidden>
Subject: Re: [Chicken-users] Re: photo album in chicken
To: chicken <address@hidden>
Message-ID: <
address@hidden>
Content-Type: text/plain; charset="us-ascii"
On Apr 30, 2006, at 9:44 AM, Reed Sheridan wrote:
>
> Also, here is a more schemely and more compact normalise-path
> function:
> <snip>
Prefer your over my offering. (Would just stripping the current-
directory elements be useful separately? Thought it might be so broke
it out for later top-level define, but ...)
(define (pathname-normalize path)
(let loop ([parts (reverse! (string-split path "/"))] [skip 0]
[acc '()])
(match parts
(() (string-join (or (and (absolute-pathname? path) (cons ""
acc)) acc) "/"))
(("." . more) (loop more skip acc))
((".." . more) (loop more (add1 skip) acc))
((path-part . more)
(if (zero? skip)
(loop more 0 (cons path-part acc))
(loop more (sub1 skip) acc))))))
That looks good, except for one thing: reverse! is from srfi-1. Use reverse instead. Also, the implementation of absolute-path? has a bug. It returns #t for a pathname starting with windows-style drive letters, but in Unix, A:/foo is a perfectly valid relative pathname. I'm not sure how to conditionalize Chicken code for Windows, or I'd fix this.
Reed Sheridan