From: Jeffrey Cunningham
Subject: Is there a way to conditionally load lisp files?
Date: 
Message-ID: <pan.2005.04.11.21.34.42.989289@cunningham.net>
I wrote several CLOS objects, each in their own files, starting with
simple ones and building up to more complex ones that include the simple
ones. They all work. When using them in other lisp codes, I load them like
this:

(load "module-1.lisp")

If, however, module-2 loads module-1 and so does module-3, I get a whole
series of ugly warning messages like this:

WARNING:
Replacing method #<STANDARD-METHOD (#<STANDARD-CLASS TRACK-CLASS>)> in
#<GENERIC-FUNCTION TRACK-TITLE> WARNING:
Replacing method #<STANDARD-METHOD (#<BUILT-IN-CLASS T> #<STANDARD-CLASS
TRACK-CLASS>)> in #<GENERIC-FUNCTION (SETF TRACK-TITLE)> WARNING:
Replacing method #<STANDARD-METHOD (#<STANDARD-CLASS TRACK-CLASS>)> in
#<GENERIC-FUNCTION TRACK-PERFORMER> WARNING:
Replacing method #<STANDARD-METHOD (#<BUILT-IN-CLASS T> #<STANDARD-CLASS
TRACK-CLASS>)> in #<GENERIC-FUNCTION (SETF TRACK-PERFORMER)>

These are apparently generated when it sees that methods are already
defined. So what I'd like to do is something like

(if (not *module-1-already-loaded*))
  (load "module-1.lisp"))

The problem is that I can't figure out a way to test for the existence of
this global parameter that doesn't bomb when it doesn't exist. Obviously,
I'm approaching this from the point of view of C, which would do something
like:

#ifndef _module_1_
#define _module_1_
<module 1 stuff goes in here>
#endif

This is no doubt not the lisp way to handle this. So, how do you handle
this situation? What's there a better way?

Thanks.

-Jeff

From: Sam Steingold
Subject: Re: Is there a way to conditionally load lisp files?
Date: 
Message-ID: <uvf6tnfed.fsf@gnu.org>
> * Jeffrey Cunningham <·······@phaavatunz.arg> [2005-04-11 14:34:44 -0700]:
>
> WARNING:
> Replacing method #<STANDARD-METHOD (#<STANDARD-CLASS TRACK-CLASS>)> in
> #<GENERIC-FUNCTION TRACK-TITLE>

is this is your only problem,
(setq clos::*gf-warn-on-replacing-method* nil)

> These are apparently generated when it sees that methods are already
> defined. So what I'd like to do is something like
>
> (if (not *module-1-already-loaded*))
>   (load "module-1.lisp"))
>
> The problem is that I can't figure out a way to test for the existence of
> this global parameter that doesn't bomb when it doesn't exist. Obviously,
> I'm approaching this from the point of view of C, which would do something
> like:
>
> #ifndef _module_1_
> #define _module_1_
> <module 1 stuff goes in here>
> #endif
>
> This is no doubt not the lisp way to handle this. So, how do you handle
> this situation? What's there a better way?

<http://www.lisp.org/HyperSpec/Body/fun_providecm_require.html>:

add a (provide "module-1") statement at the begining of "module-1.lisp"
and do
(require "module-1")
(require "module-2")
&c.

(ignore the note that PROVIDE and REQUIRE are deprecated).

see also <http://clisp.cons.org/impnotes/system-dict.html#require>


-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.mideasttruth.com/> <http://www.palestinefacts.org/>
<http://www.camera.org> <http://pmw.org.il/> <http://www.iris.org.il>
Nostalgia isn't what it used to be.
From: Jeffrey Cunningham
Subject: Re: Is there a way to conditionally load lisp files?
Date: 
Message-ID: <pan.2005.04.11.22.47.09.595545@cunningham.net>
On Mon, 11 Apr 2005 17:59:38 -0400, Sam Steingold wrote:

> is this is your only problem,
> (setq clos::*gf-warn-on-replacing-method* nil)

I prefer to leave warnings on so if (when) I do something dumb I have some
clues to track it down.

> <http://www.lisp.org/HyperSpec/Body/fun_providecm_require.html>:
> 
> add a (provide "module-1") statement at the begining of "module-1.lisp"
> and do
> (require "module-1")
> (require "module-2")
> &c.
> (ignore the note that PROVIDE and REQUIRE are deprecated).
> 
> see also <http://clisp.cons.org/impnotes/system-dict.html#require>

This seems to work really well, so I'll do it this way for now. Thanks for
the tip!

And thanks to the others for pointing out asdf. I actually installed it a
couple months ago, but haven't figured out how to use it yet. Its on my
list...

Regards,
-jeff cunningham
From: Kenny Tilton
Subject: Re: Is there a way to conditionally load lisp files?
Date: 
Message-ID: <0iC6e.1676$yl6.287102@twister.nyc.rr.com>
You probably want to spend a little time learning ASDF:

    http://www.cliki.net/asdf

kenny

Jeffrey Cunningham wrote:
> I wrote several CLOS objects, each in their own files, starting with
> simple ones and building up to more complex ones that include the simple
> ones. They all work. When using them in other lisp codes, I load them like
> this:
> 
> (load "module-1.lisp")
> 
> If, however, module-2 loads module-1 and so does module-3, I get a whole
> series of ugly warning messages like this:
> 
> WARNING:
> Replacing method #<STANDARD-METHOD (#<STANDARD-CLASS TRACK-CLASS>)> in
> #<GENERIC-FUNCTION TRACK-TITLE> WARNING:
> Replacing method #<STANDARD-METHOD (#<BUILT-IN-CLASS T> #<STANDARD-CLASS
> TRACK-CLASS>)> in #<GENERIC-FUNCTION (SETF TRACK-TITLE)> WARNING:
> Replacing method #<STANDARD-METHOD (#<STANDARD-CLASS TRACK-CLASS>)> in
> #<GENERIC-FUNCTION TRACK-PERFORMER> WARNING:
> Replacing method #<STANDARD-METHOD (#<BUILT-IN-CLASS T> #<STANDARD-CLASS
> TRACK-CLASS>)> in #<GENERIC-FUNCTION (SETF TRACK-PERFORMER)>
> 
> These are apparently generated when it sees that methods are already
> defined. So what I'd like to do is something like
> 
> (if (not *module-1-already-loaded*))
>   (load "module-1.lisp"))
> 
> The problem is that I can't figure out a way to test for the existence of
> this global parameter that doesn't bomb when it doesn't exist. Obviously,
> I'm approaching this from the point of view of C, which would do something
> like:
> 
> #ifndef _module_1_
> #define _module_1_
> <module 1 stuff goes in here>
> #endif
> 
> This is no doubt not the lisp way to handle this. So, how do you handle
> this situation? What's there a better way?
> 
> Thanks.
> 
> -Jeff

-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: JP Massar
Subject: Re: Is there a way to conditionally load lisp files?
Date: 
Message-ID: <eqlm519lqr0vmfqkhgrrnnikk6v36vocof@4ax.com>
On Mon, 11 Apr 2005 14:34:44 -0700, Jeffrey Cunningham  
>
>(if (not *module-1-already-loaded*))
>  (load "module-1.lisp"))
>
>The problem is that I can't figure out a way to test for the existence of
>this global parameter that doesn't bomb when it doesn't exist. 

(if (and (boundp '*foo*) (not *foo*)) ...
From: Jeffrey Cunningham
Subject: Re: Is there a way to conditionally load lisp files?
Date: 
Message-ID: <pan.2005.04.13.02.02.29.221428@cunningham.net>
On Mon, 11 Apr 2005 22:07:27 -0700, JP Massar wrote:

> (if (and (boundp '*foo*) (not *foo*)) ...

Great! Seems like with lisp there's always a way.

-jeff cunningham
From: Pascal Costanza
Subject: Re: Is there a way to conditionally load lisp files?
Date: 
Message-ID: <3c0a6qF6ihh07U1@individual.net>
Jeffrey Cunningham wrote:
> I wrote several CLOS objects, each in their own files, starting with
> simple ones and building up to more complex ones that include the simple
> ones. They all work. When using them in other lisp codes, I load them like
> this:
> 
> (load "module-1.lisp")
> 
> If, however, module-2 loads module-1 and so does module-3, I get a whole
> series of ugly warning messages
[...]

> So, how do you handle
> this situation? What's there a better way?

You need a system definition facility, like asdf or mk-defsystem or 
something vendor-specific, that allows you to declare which modules 
depend on which other modules, and automatically figures out the 
dependencies according to your declarations.


Pascal

-- 
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/
From: Kent M Pitman
Subject: Re: Is there a way to conditionally load lisp files?
Date: 
Message-ID: <ur7hfo2ex.fsf@nhplace.com>
Pascal Costanza <··@p-cos.net> writes:

> Jeffrey Cunningham wrote:
> > I wrote several CLOS objects, each in their own files, starting with
> > simple ones and building up to more complex ones that include the simple
> > ones. They all work. When using them in other lisp codes, I load them like
> > this:
> > (load "module-1.lisp")
> > If, however, module-2 loads module-1 and so does module-3, I get a
> > whole
> > series of ugly warning messages
> [...]
> 
> > So, how do you handle
> > this situation? What's there a better way?
> 
> You need a system definition facility, like asdf or mk-defsystem or
> something vendor-specific, that allows you to declare which modules
> depend on which other modules, and automatically figures out the
> dependencies according to your declarations.

Certainly.  But it's worth pointing out, as well, that such facilities
don't work by magic.  I have plenty of "foothold" files that just do
things like this.  [untested, caveat emptor, offered mostly so you can
know what functions you should go look up.  this is the kind of reflective
capability lisp excels at and which is not as easily accessible in other
languages.]

 (unless (let ((package (find-package "FOO")))
           (when package
             (let ((symbol (find-symbol "BAR" package))) 
               ;; on rare occasion, the second value from find-symbol is 
               ;; helpful here, not just the primary value [symbol], in which
               ;; case you might need MULTIPLE-VALUE-BIND instead of LET.
              (when (and symbol
                         (boundp symbol)
                         (eq (symbol-value symbol) 't)) ;or whatever value you want to check for
                ;; if we got here, the facility must have been loaded correctly,
                ;; so return t for the UNLESS conditional above, to bypass reloading it.
                t))))
   (load "whatever"))

but yes, it is packaged up better in most defsystem facilities.