[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] "include" filename resolution



On Mon 08 Aug 2011 19:10, Per Bothner <per@x> writes:

> "load" should probably relative to the working directory (for
> compatibility with historical practice if nothing else), but
> loading files relative to the "application" is probably more useful.

Guile does something terrible here.

;;; Load is tricky when combined with relative paths, compilation, and
;;; the filesystem.  If a path is relative, what is it relative to?  The
;;; path of the source file at the time it was compiled?  The path of
;;; the compiled file?  What if both or either were installed?  And how
;;; do you get that information?  Tricky, I say.
;;;
;;; To get around all of this, we're going to do something nasty, and
;;; turn `load' into a macro.  That way it can know the path of the
;;; source file with respect to which it was invoked, so it can resolve
;;; relative paths with respect to the original source path.
;;;
;;; There is an exception, and that is that if the source file was in
;;; the load path when it was compiled, instead of looking up against
;;; the absolute source location, we load-from-path against the relative
;;; source location.

and then

(define-syntax load
  (make-variable-transformer
   (lambda (x)
     (let* ((src (syntax-source x))
            (file (and src (assq-ref src 'filename)))
            (dir (and (string? file) (dirname file))))
       (syntax-case x ()
         ((_ arg ...)
          #`(load-in-vicinity #,(or dir #'(getcwd)) arg ...))
         (id
          (identifier? #'id)
          #`(lambda args
              (apply load-in-vicinity #,(or dir #'(getcwd)) args))))))))

FWIW...

Andy
-- 
http://wingolog.org/

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports