[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.
(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 ...))
(apply load-in-vicinity #,(or dir #'(getcwd)) args))))))))
Scheme-reports mailing list