guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

guile 1.4 module system


From: Alex Schroeder
Subject: guile 1.4 module system
Date: Sat, 15 Sep 2001 00:02:32 +0200
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7

This is the first time I've actually started to use modules, so bear
with me.  (And I haven't been able to build guile from CVS until now.)

I have the following files:

report2txt.scm
report2xml.scm
admin.scm

report2txt.scm and report2xml.scm are two scripts that can be run from
the command line.  They transform a report into either plain text or
XML.  A report is a file with a list structure.  Actually it can be
seen as a Scheme program.  Here is the start of such a report file:

   (report (myself "Alex" (list (weapon "Sternenspalter" ...

What report2txt.scm and report2xml.scm do, therefore, is 1. define
different functions called report, myself, weapon, etc. 2. load the
report file, thus producing the output.

admin.scm is also a script that is run from the command line.  It is
used to create either plain text or XML reports for several reports.

What I want in admin.scm, therefore, is something like this:

    ...
    (load "report2txt.scm")
    (load file)
    ...

The most important question to me now is wether I have used the module
system as it ought to be used.  And then I have one or two more...  :)

What I actually did, is this:


I wanted report2txt.scm to be contain a module.  So instead of just
defining functions, I followed the instructions in the guile-ref.
Here's the start of report2txt.scm.

    ;;; Reporting

    (define-module (nulligarchie text-report))

    (define-public (report myself . regions)
      (title (string-append "Report for " (myself 'name)))
      (report-myself myself)
      (if (null? regions)
          (report-imprisoned)
          (for-each report-region regions)))
    ...

Remember that admin.scm will use two modules that export the same
names.  The question is therefore how will I access these?

Here's what I did.  I've included a call to use-modules somewhere deep
inside my function.

(load-module "report2txt.scm")
...
(define (write-txt-reports)
  (define (report file)
    (use-modules (nulligarchie text-report))
    (let ((output (string-append file ".txt")))
      (with-output-to-file output
        (lambda ()
          (load file)))))
  (define (write dirs)
    (let ((file (readdir dirs)))
      (if (not (eof-object? file))
          (begin
            (set! file (string-append reportdir "/" file))
            (display "  ")
            (display file)
            (if (regular? file)
                (report file)
                (display " [skipped]"))
            (newline)
            (write dirs)))))
  (display "Creating Text Reports")
  (newline)
  (write (opendir reportdir)))

Questions:

* How do I "import" a module?  I've used load-module, but that's just
  because it looked good when I tried (apropos "load").  What would be
  the correct way to do this?  There is no relationship between the
  module name and the file name, right?  (As in Emacs require, for
  example.)

* I saw in recent articles that Guile 1.5 will allow uses-module only
  at the top level.  How can I tell Guile what namespace to use when
  loading a file, then?

Alex.
-- 
http://www.geocities.com/kensanata/
Coffee should be black as hell, strong as death and sweet as love.
        -- Turkish proverb



reply via email to

[Prev in Thread] Current Thread [Next in Thread]