[Top][All Lists]

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

Re: modules as scripts

From: Neil Jerram
Subject: Re: modules as scripts
Date: 05 Oct 2001 20:06:52 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

>>>>> "Alex" == Alex Schroeder <address@hidden> writes:

    Alex> Michael Livshin <address@hidden> writes:
    >> #!/bin/sh # aside from this initial boilerplate, this is
    >> actually -*- scheme -*- code main="(module-ref (resolve-module
    >> '(scripts snarf-check-and-output-texi)) 'main)" exec
    >> ${GUILE-guile} -l $0 -c "(apply $main (cdr (command-line)))"
    >> "$@" !#
    >> the module has to have a procedure named `main', and there's
    >> even no need to export it.

    Alex> Thanks for the pointer.

    Alex> I experimented a bit with this, and ran into another
    Alex> problem.  The data or scheme program is a file with a sexp
    Alex> such as (report ...).

    Alex> "report" is a function in the module itself.  There for the
    Alex> "main" function will read the data file, and the sexp has to
    Alex> be evaluated in the top-level environment (I hope I am using
    Alex> the terms correctly).  In the following example, I get the
    Alex> error that the variable report is undefined.

The problem here is that, although `main' is defined inside the
(my-test) module, it is invoked with the current module being
(guile).  So the code from `test' that is executed by `eval' only has
access to definitions in (guile), and these definitions don't include
`report'.  (Note that it isn't enough for (my-test) to export
`report'; it's also necessary for (guile) to import from (my-test)
using a command such as `(use-modules (my-test))'.)

A couple of possibilities that should fix this are...

1. Replace `(interaction-environment)' by `(resolve-module

2. Instead of eval'ing a single expression, load the `test' file using
   `primitive-load'; then you could add, as the first line in `test':

        (use-modules (my-test))


reply via email to

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