On Sat, Apr 24, 2004 at 09:52:12AM +1000, Damian Conway wrote: : My proposal for that issue is just: : : module Bar; : : use Foo «foo»; : : sub foo is export {...}
That's on the right track, but has some difficulties, insofar as it's not clear that the intent is to redefine "foo" retroactively rather than actively. And it doesn't necessarily work for variables, nor does it tell the "use" whether you were intending to import «foo» as a package name or a lexical name. What I've been envisioning in that regard involves making declarations that simultaneously look like declarations and can have their names "harvested" for use by the C<use>. As a "placeholder", let's postulate a funny macro called "namely", that works something like this: module Bar; use Foo namely( my sub foo is export {...} my Int $foocount is export(:MANDATORY); our sub bar {...} my %huz ::= %zah; ); which, to the C<use>, ends up looking something like use Foo «foo $foocount bar %zah» except that the exporter presumably has access to all the extra information it needs to make sure the types and renamings stay sane. The syntax is, of course, totally up for grabs, but please note that we can't use curlies instead of parentheses, or the scoping goes all wrong. The alternative approach is to have a means of marking the "use" as lazy, and a way of marking each individual declaration as an alias from a particular module. That can get rather more verbose though. use Foo :lazily; my sub foo is from(Foo) is export {...} my Int $foocount is from(Foo) is export(:MANDATORY); our sub bar is from(Foo) {...} my %huz ::= %Foo::zah; On the other hand, the renaming syntax is a little more toward. Maybe they're all renamings: my sub foo is export ::= Foo::foo; my Int $foocount is export(:MANDATORY) ::= $Foo::foocount; our sub bar ::= Foo::bar; my %huz ::= %Foo::zah; That gets rid of the spurious {...}, at least. At the expense of colon overload, though... And it's not like we can't do that already. It's the moral equivalent of Perl 5's glob aliasing. As such it's pretty darn ugly. Which means it's fine for exceptions, but lousy for normal use. The main reason for separate declarations in normal use is to specify whether you want to import lexically or packagely. So a more minimal approach is to allow use Foo my &foo, my $foocount, our &bar; for the normal declarations (ignoring re-exportation issues), and then resort to ::= for renamings. If we make lexical importation the default, that reduces to use Foo «foo $foocount», our &bar; Of course, for re-export you'd have to say use Foo my &foo is export, my $foocount is export(:MANDATORY), our &bar; For that to work, C<my> and C<our> would have to be sufficiently context sensitive to know when they were in use list. The alternative is a macro like namely(), which would also have the benefit of letting you use semicolons between declarations rather than commas. Larry