Subject: Re: Load path question
From: rpw3@rpw3.org (Rob Warnock)
Date: Sat, 11 Aug 2007 20:19:23 -0500
Newsgroups: comp.lang.lisp
Message-ID: <K8udnV0ycJOG_SPbnZ2dnUVZ_gmdnZ2d@speakeasy.net>
Rainer Joswig  <joswig@lisp.de> wrote:
+---------------
| Other than that write it yourself. In the great tradition of untested
| and unfinished code on c.l.l ;-) :
| (defparameter *directories-to-search* (list ... ))
| (defun my-load-using-directories (name
|                                   &optional (dirs *directories-to-search*))
|   (loop for dir in dirs
|         for file = (merge-pathname name dir)
|         for file-exists = (probe-file file)
|         when file-exists do (load file)
|         unless file-exists))
+--------------

Minor correctness & style quibbles[1]:

0. MERGE-PATHNAMES, not MERGE-PATHNAME.

1. The final UNLESS clause is missing a "selectable-clause" after
    the test form. You probably meant to use UNTIL instead.

2. UNTIL would be correct, but that style of LOOP termination might
   be a bit obscure. I would suggest this instead, which also has
   the advantage of returning a potentially-useful value from LOAD:

   (defun my-load-using-directories (name
				     &optional (dirs *directories-to-search*))
     (loop for dir in dirs
           for file = (merge-pathnames name dir)
           for file-exists = (probe-file file)
           when file-exists
	     do (return (load file))))

And that version, now *very* lightly tested, does seem to work:

    > *directories-to-search*

    ("home:" "home:tmp/" "home:src/try/")
    > (my-load-using-directories "foo")

    ; Loading #P"/u/rpw3/tmp/foo".
    hello, world!
    T
    > 

-Rob

[1] In the great tradition of quibbling about untested and
    unfinished code on c.l.lisp.  ;-)

[2] And in the equally great tradition of generalizing tiny CL examples
    to their maximal -- dare I say, overblown?!? -- generality, I offer
    this additional version:   ;-}   ;-}

    > (defun my-load-using-directories (name
					&rest rest
					&key (directory-list
					      *directories-to-search*) 
					&allow-other-keys)
	 (loop for dir in directory-list
	       for file = (merge-pathnames name dir)
	       for file-exists = (probe-file file)
	       when file-exists
		 do (return (apply #'load file :allow-other-keys t rest))))

    MY-LOAD-USING-DIRECTORIES
    > (my-load-using-directories "foo" :verbose nil :print t)

    hello, world!
    ; NIL
    ; (EXPT 2 100)
    ; =
    ; 1267650600228229401496703205376
    T
    > 

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