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

Re: require



    Consider the following piece of code:
    
        (in-package 'me)
        (require 'foo)    ; Module FOO creates package FOO
        (foo:some-function)
    
    There is nothing wrong with this when you run it through the interpreter,
    but it dies when you try to compile it.  Why?  Because the call to REQUIRE
    doesn't get evaluated at compile time, thus module FOO doesn't get loaded,
    package FOO isn't created and SOME-FUNCTION isn't made an external symbol.
    The manual has taken some pains to describe how you should order the calls
    to set up the package environment and load various modules at the beginning
    of each file, but it doesn't seem to interact with the compiler very well.
    
Your example demonstrates why REQUIRE should implicitly be evaluated by the
compiler.  I believe one can also deduce this fact from the examples in the
chapter on packages (assuming them to be compilable), but it is not stated
explicitly in the definition.

    Making REQUIRE so it is always implicitly (eval-when (eval compile load)...)
    would solve the problem, but this would create problems, too.  I have at
    least one utility where I want one module loaded at compile time to provide
    definitions for some rather hairy macros, and another (much smaller) module
    around at load time which contains a few functions for runtime support.
    
It would be nice if (EVAL-WHEN (EVAL LOAD) (REQUIRE ...)) did the trick, but
unfortunately EVAL-WHEN has been explicitly defined NOT to be able turn off
implicit compile-time evaluation.  I believe that it should do this, and
argued so a long time ago.

  Alan
-------