guile-user
[Top][All Lists]
Advanced

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

Re: modules as scripts


From: Alex Schroeder
Subject: Re: modules as scripts
Date: Sun, 16 Sep 2001 19:16:55 +0200
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7

Ok, further down the line and using Guile from CVS.

I have a file called "report2txt.scm".  In it, I define a module.  The
main function in the module is called report.  I use define-public to
export it.

In order to write automated tests I want to call this module as a
script from the command line, too.  So I added a main function and the
necessary lines at the beginning of the file.  I don't want to use
define-public to export main.

Anyway, here are some of the things I tried.  All the errors make
sense to me; the question is: what is the correct way of solving my
problem?

When I use this order, I get "ERROR: Unbound variable: main" because
main is obviously hidden within the module.

#! /usr/local/bin/guile \
-e main -s
!#
(define-module (report2txt))
(define-public (report myself . regions) ...)
...
(define (main args) ...)

When I use the following, I cannot call report from within main.  I
get "ERROR: Unbound variable: report".

#! /usr/local/bin/guile \
-e main -s
!#
(define (main args) ...)
(define-module (report2txt))
(define-public (report myself . regions) ...)
...

Finally, the following does not work, either.  I get "ERROR: no code
for module (report2txt)".

#! /usr/local/bin/guile \
-e main -s
!#
(use-modules (report2txt))
(define (main args) ...)
(define-module (report2txt))
(define-public (report myself . regions) ...)
...


Maybe this is an inherent limitation -- something that is a module
cannot run standalone?  I guess what I'm really looking for is
something akin to Python's "if __name__=='__main__':" construct at the
end of files.

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]