This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: difference between (load "package.foo.bar") and require?


Hi,

[this is a late follow-up to a thread I started in May 2004
http://sources.redhat.com/ml/kawa/2004-q2/ ]

Per Bothner wrote:
>Require works on *modules*.  In principle a module can be any class,
>whether compiled from Scheme and Java, but what it does with the
>module depends on the public fields of the module.  Basically,
>it adds a new binding to the *local* environment for each public
>field.

>> When loading a file, all top-level definitions are added to the top-level
>> interaction environment. The loading is done by 'load' using a custom class
>> loader. That's why it does not take into account the .jar files.
>It does use the same ClassLoader as when you're evaluating expressions,
>which is an ArrayClassLoader.  If you load a file-compiiled-to-zip, it
>uses a separate ZipLoader.

It looks like I found a way to realize what I wanted:
o use a .jar file of compiled Scheme instead of having classes extracted
o load a config.scm file at run-time that overrides values from the compiled classes

I write this e-mail to draw people's attention to my recent discovery:

Using a type declarations like
-------- options.scm
(define Defaults :: <list> '((file "foo.txt"))) ; doesn't work
(define (get-option name) (assq name Defaults))
in a file prevents the Defaults variable from being overriden by the config file!

Remove the type declaration and the get-option function will see overiding values, coming from either fluid-let or from loading the configuration file via (load "config.scm")!
-------- config.scm contains:
(define Defaults '((file "bar"))) ; set! also works
;(set! Defaults '((file "bar")))
;set! is conceptually more adequate as override.

-------- main.scm uses:
(define (load-command)
  (require <jch.options>) ; load would not recognize .jar files
  (load "config.scm")
  (format #t "Using ~S~%" (get-option 'file))
  (fluid-let ((Defaults '((file "fluid"))))
    (format #t "Using ~S~%" (get-option 'file))))

I originally added the type declaration
a) out of Common Lisp habit and
b) hope for run-time diagnostics when assigning values of incorrect types.

There's no error message for b) and now I'll be aware of this side effect of adding type declarations.

I also tried this in options.scm:
(define Defaults :: <list> '((file "foo.txt"))) ; doesn't work, should be overiden later
(set! Defaults Defaults)
to try to tell the compiler that the value is not a static constant, but that did not change behaviour.

Regards,
	Jorg Hohle


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]