[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 
mzscheme
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)
      (list)
      (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)
      (list)
      (cons
       (if (char=? (car l) #\\)
           #\/
           (car l))
       (backslash->slash (cdr l)))))
    (list->string
     (backslash->slash
      (string->list
       (path->string (make-relative name))))))

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

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

Hans

>
> John 




Posted on the users mailing list.