[plt-scheme] dynamic require

From: Hans Oesterholt-Dijkema (hdnews at gawab.com)
Date: Sun Jun 5 17:34:36 EDT 2005

> If I understand your complaint correctly, you're expecting 
> module-paths to have a platform-specific separator character, though 
> in MzScheme they don't. As I understand it, this 
> platform-insensitivity is key in making it possible to write 
> cross-platform code.

Nice, however, I didn't give the whole picture. Using 'build-path', 
mzscheme itself
returns a path with backslashes on windows. With this returned path of 
I tried to do a dynamic-require. I solved my problem as follows:

(define (find-driver driver)

  (define (ups path)
    (define (ups l)
      (if (null? l)
      (if (or (char=? (car l) #\/)
          (char=? (car l) #\\))
          (cons 'up (ups (cdr l)))
          (ups (cdr l)))))
    (ups (string->list (path->string path))))

  (define (make-relative path)
    (let ((p (path->string path)))
      (if (string=? (substring p 1 2) ":")
      (make-relative (build-path (substring p 3 (string-length p))))
      (apply build-path (append (ups (current-directory)) (list path))))))

  (define (get-relative-name name)
    (define (backslash->slash l)
      (if (null? l)
       (if (char=? (car l) #\\)
           (car l))
       (backslash->slash (cdr l)))))
       (path->string (make-relative name))))))

  (define (try-driver P)
    (if (null? P)
    (let ((name (build-path (car P) "oodb" driver)))
      (log-info "Trying path '" (path->string name) "' for driver '" driver)
      (if (file-exists? name)
          (get-relative-name name)
          (try-driver (cdr P))))))

  (let ((paths (cons (build-path (current-directory))
    (try-driver paths)))


> John 

Posted on the users mailing list.