On Tue, Jul 12, 2005 at 12:15:30PM +0000, Ingo Blechschmidt wrote:
: Hi,   
:    
: what do use and require evaluate to?  
:   
: S06 suggests it's probably some kind of Module object:   
:   The result of a use statement is a (compile-time) object that also has   
:   an .assuming method, allowing the user to bind parameters in all the   
:   module's subroutines/methods/etc. simultaneously:   
:      
:       (use IO::Logging).assuming(logfile => ".log")   
:    
: We could make (use Foo) evaluate to the class object Foo,   
: allowing:   
:    
:     my $foo = (use Foo).new(...);   

I don't think it's wise to presume a magical binding between the package
name and the file name in this case.

: Alternatively, we could go the Perl 5 way and return the   
: last thing evaluated in Foo.pm (which might be a Module   
: object, assuming that module Foo {...} evaluates to Foo).   

That works for me.  I would note that when you say

    module Foo;
    ...

it is equivalent to

    module Foo {
        ...
    }

so the first form does in fact return the module as the last (and only)
statement in the file.  Presumbaly one can override this with an
explicit return.

: What do successive uses of use and require evaluate to?   
: Perl 5 is inconsistent:   
:    
:     $ cat > Foo.pm   
:     package Foo; 42;   
:     $ perl -we 'warn require Foo; warn require Foo'   
:     42 at -e line 1.   
:     1 at -e line 1.   
:    
: I'd like Perl 6's use and require to return the same thing.   

They will.  It'll be the "last thing", as defined above to usually
mean "the whole thing".  In the case of separate compilation this
may actually be a proxy or stub for the module or class that is just
smart enough to manage the interface to the module/class without
necessarily knowing the implementation.  (This does imply that
used modules must be compiled no later than "use" time, since we
can't know what the module exports without compiling it.)

: In Perl 5, %INC maps the partial path names of the modules   
: loaded to their absolute ones. What should the keys and values   
: of %*INC be in Perl 6?   

It's not clear that Perl 6 will use the same search strategy for
modules, so there may not even be a %INC, or if there is, there's no
guarantee what the keys and values will really be. This has not yet
been specified.  But searching a path of directories is certainly
one thing that slows down Perl 5 startup times.  Whether or not the
Perl 6 library system is implemented using a database or flat files,
the search for a module matching various criteria will likely be in
some kind of index rather than doing probes on the bare filesystem.
There might well be a %INC, but its value might well be that very
package and/or proxy object we were discussing above, and what file
it came from might just be part of its metadata.  Also, if the key
of %INC is the short name of a module, than it really has to be
kept per lexical scope, since different lexical scopes are allowed
to have different mappings from short names to long, so that we
can have dependencies on two different versions of the same module
simultaneously (to the extent allowed by shared resources).

In short, Perl 5 code that assumes too much knowledge about %INC
will have to be recoded to work under Perl 6.

Larry

Reply via email to