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

file loading query

re: 1. Anybody know a *portable* trick I can use to get embedded calls to LOAD
    to use the parent file's pathname as a default?

You needn't be a privileged implementor to use Lucid's idea.

This should be portable:

(defvar *my-load-pathname* nil)

(defun my-load (partial-path)
  (let ((*my-load-pathname* (merge-pathnames partial-path *my-load-pathname*)))
    (load *my-load-pathname*)))

and replace all calls to load in files with calls to my-load, e.g.,

(my-load "What-a-moaning")

A more general thing involving twiddling the prefix of a directory tree
from which embedded loads will occur in various subdirectories might be

(defun load-from-subtree (partial-path path-function)
  (let ((*my-load-pathname* (funcall path-function partial-path *my-load-pathname*)))
    (load *my-load-pathname*)))

and replace embedded load calls with load-from-subtree.  Typically the
path-function will concatenate the directories of *my-load-pathname* and
partial-path, or something.  At least on Lucid 3.0, merge-pathnames serves
as such a function, as in (merge-pathnames "arith/bignum" "~/broken/mork.bin").

Jeff Greif
Inference Corp.