Re: [Scheme-reports] "include" filename resolution Denis Washington (08 Aug 2011 11:54 UTC)
Re: [Scheme-reports] "include" filename resolution John Cowan (08 Aug 2011 12:06 UTC)
Re: [Scheme-reports] "include" filename resolution Per Bothner (08 Aug 2011 17:12 UTC)
Re: [Scheme-reports] "include" filename resolution Andy Wingo (12 Aug 2011 20:31 UTC)
Re: [Scheme-reports] "include" filename resolution John Cowan (12 Aug 2011 22:29 UTC)

Re: [Scheme-reports] "include" filename resolution Andy Wingo 12 Aug 2011 20:29 UTC

On Mon 08 Aug 2011 19:10, Per Bothner <per@bothner.com> 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@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports