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: Module of loaded files


Per Bothner <per@bothner.com> wrote:
> Generally, if you're compiling and using modules, you should avoid
> load.  The static bindings of modules provide both better name space
> management, and better performance.  

That makes sense and in fact I rarely use load.  

In case anyone is interested, I'll describe what what we're doing: There
is an application where the user types in a "script" with some
specialized commands and the a driver program runs that script.  The
language of the script happens to be Scheme (although the user may not
know that) and the specialized commands are Scheme procedures.

The new working implementation makes a temporary file and puts a
(require <M>) and the content of the original file in the temp file.
Then we load the temp file.  So:

    unix% hammer simple-load-test.hammer

ends up being handled by:

    ;; Load the fname with the standard header.  We need this to make sure
    ;; that loaded file has access to the Hammer definitions.
    (define (process fname)
      (let ((tmp (make-temporary-file)))
        (try-finally
         (begin
           (let ((in (open-input-file fname))
                 (out (open-output-file tmp)))
             (dolist (r *STANDARD-REQUIRES*) 
               (format out "~S~%" r))
             (copy-ports in out)
             (close-output-port out)
             (close-input-port in)
             (load tmp)))
         (delete-file tmp))))

Where *STANDARD-REQUIRES* has the (require <M>) equivalent.

> I've thought about adding an option to emit a warning or error at
> compile-time is a name is undefined, forcing all names to be lexically
> bound using modules.  

Great idea.

Regards,
Chris Dean


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