Subject: Re: Load path question
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 14 Aug 2007 03:01:33 -0500
Newsgroups: comp.lang.lisp
Message-ID: <p7-dnTNz5sDA_FzbnZ2dnUVZ_tuonZ2d@speakeasy.net>
sj <jones57@swbell.net> wrote:
+---------------
| Thanks for all the replies.  I ended up taking a slightly different
| approach factoring out load from the directory search code. I also
| added a list of possible file extensions so the algorithm will match
| "foo" to both "foo" and "foo.lisp" or whatever extension is desired. 
+---------------

I think you need to make it be a tiny bit smarter than this.
For example, on an x86 platform when you ask CMUCL to (LOAD "foo"),
it first tries "foo", then "foo.x86f" [its extension for hard-
ompiled code on x86], then "foo.lbytef" [its extension for
byte-compiled code on LittleEndian machines], then "foo.fasl"
[the generic extension for compiled code], then finally "foo.lisp",
"foo.l", "foo.cl", and "foo.lsp", in that order.

Plus, by default, if you have both a compiled version [e.g.,
"foo.x86f"] and a source version [e.g., "foo.lisp"] and the
latter is newer than the former, it will warn you [but load
the older binary version anyway]:

    cmu> (load "foo")
    Warning:  Loading object file /u/rpw3/foo.x86f,
    which is older than the presumed source:
      /u/rpw3/foo.lisp.

    ; Loading #P"/u/rpw3/foo.x86f".
    Hi! My name is #P"/u/rpw3/foo.x86f".
    T
    cmu> 

You can override this and get very useful behavior by specifying
the non-standard :IF-SOURCE-NEWER keyword with the :COMPILE option,
like this:

    cmu> (load "foo" :if-source-newer :compile)

    ; Python version 1.1, VM version Intel x86 on 14 AUG 07 12:47:55 am.
    ; Compiling: /u/rpw3/foo.lisp 14 AUG 07 12:47:51 am

    ; Byte Compiling Top-Level Form: 

    ; foo.x86f written.
    ; Compilation finished in 0:00:00.

    ; Loading #P"/u/rpw3/foo.x86f".
    Hi! My name is #P"/u/rpw3/foo.x86f".
    T
    cmu>

Do it again, and it doesn't recompile, of course:

    cmu> (load "foo" :if-source-newer :compile)

    ; Loading #P"/u/rpw3/foo.x86f".
    Hi! My name is #P"/u/rpw3/foo.x86f".
    T
    cmu> 

Whichever implementation of CL you're using will likely have
similar behavior regarding defaulting file types and possibly
similar extensions builtin, so you want to make sure your
WHICH-FILE is at *least* as smart as your implementation's
builtins w.r.t. source vs. binary, and also modification dates.


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607