[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] photo album in chicken
From: |
Kon Lovett |
Subject: |
Re: [Chicken-users] photo album in chicken |
Date: |
Sun, 30 Apr 2006 10:34:09 -0700 |
Hi Ashish,
Two points:
1) If anyone really cares the imlib egg can be easily modified to
handle garbage images, will keeping an explicit destroy for backward
compatibility.
2) In "fileutils.scm" suggest something like the following (sorry for
the renaming, me spell U.S. "English"):
(use srfi-1 srfi-13 srfi-26 posix utils)
(define (pathname-normalize path)
(let (
[collapse-current-directories
(lambda (splits)
(reverse! (remove (cut string=? "." <>) splits)))])
(let loop ([parts (collapse-current-directories (string-split
path "/"))] [norm-parts '()])
(if (null? parts)
(string-join norm-parts "/")
(let ([cur (car parts)] [nxt (cdr parts)])
(if (and (not (null? nxt)) (string=? ".." cur))
(if (string=? ".." (car nxt))
(loop nxt norm-parts)
(loop (cdr nxt) norm-parts))
(loop nxt (cons cur norm-parts))))))))
(define (make-directory! dir)
(let loop ([dir (pathname-normalize dir)])
(unless (or (not dir) (string-empty? dir))
(unless (directory? dir)
(loop (pathname-directory dir))
(create-directory dir)))))
- SRFI-26 ('cut' above) is really useful.
- The bang '!' on the end of make-directory! is to emphasize the side-
effecting nature.
- You may want to use the utf8 egg to handle UNICODE string pathnames.
- Needs chicken-2.223+ so decompose-pathname "correctly" strips
trailing directory-separator '/' from the directory portion.
(pathname-directory built on
- Something like the above probably should go into the library, used
all over the place.
Best Wishes,
Kon