Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

namespaces, a single colon to separate HLL prefix?

8 views
Skip to first unread message

Allison Randal

unread,
Jul 6, 2006, 3:30:14 AM7/6/06
to perl6-l...@perl.org
Quick question, is there a syntax specified in Perl 6 for referring to
namespaces from other languages?

I'm reviewing the namespaces PDD and want to update this snippet:
------
IMPLEMENTATION EXAMPLES: Suppose a Perl program were to import some Tcl
module with an import pattern of ``c*'' -- something that might be
expressed in Perl 6 as use tcl:Some::Module 'c*'. This operation would
import all the commands that start with 'c' from the given Tcl namespace
into the current Perl namespace. This is so because, regardless of
whether 'c*' is a Perl 6 style export pattern, it is a valid Tcl export
pattern.

{XXX - Is the ':' for HLL approved or just proposed? Somebody familiar
with Perl 6 please fix the example in the preceding paragraph to use the
currently planned syntax for importing modules from other languages.}
------

Thanks,
Allison

Audrey Tang

unread,
Jul 6, 2006, 10:40:21 AM7/6/06
to Allison Randal, perl6-l...@perl.org

在 2006/7/6 上午 3:30 時,Allison Randal 寫到:

The : form is approved and canonical (line 303, the Modules spec, aka
S11.pm version 14).

use perl5:DBI;

However, currently it's only available at use/require line.
Afterwards, the user simply say:

my $dbh = DBI.connect(...);

Though I think this:

my $dbh = perl5:DBI.connect(...)

can be made to work, as it's currently parsefail, thought there is a
marginal case:

my $dbh = perl5:DBI; # currently parsed as perl5(:DBI)

but we can say that for each HLL-qualified module name, it's a single
token and is therefore recognized first.

Does that sound sane? If yes, S11 can be updated to reflect that.

Thanks,
Audrey

PGP.sig

Larry Wall

unread,
Jul 6, 2006, 12:09:08 PM7/6/06
to perl6-l...@perl.org
On Thu, Jul 06, 2006 at 10:40:21AM -0400, Audrey Tang wrote:
: The : form is approved and canonical (line 303, the Modules spec, aka
: S11.pm version 14).
:
: use perl5:DBI;
:
: However, currently it's only available at use/require line.
: Afterwards, the user simply say:
:
: my $dbh = DBI.connect(...);
:
: Though I think this:
:
: my $dbh = perl5:DBI.connect(...)
:
: can be made to work, as it's currently parsefail, thought there is a
: marginal case:
:
: my $dbh = perl5:DBI; # currently parsed as perl5(:DBI)
:
: but we can say that for each HLL-qualified module name, it's a single
: token and is therefore recognized first.
:
: Does that sound sane? If yes, S11 can be updated to reflect that.

It's only sane if we require the predeclaration of the language higher
in the lexical scope. Suppose we try to maintain a secret canonical
list, and then suppose someone adds a language 'q', for instance?
But after a "use q:mumble" we can certainly recognize "q:", presumably
forcing people to write "q :mumble" for the rest of the lexical scope
if they want a mumbled quote. Alternately we could force explicit
declaration of all foreign namespaces:

use namespace <perl5 q>;
...
use q:QueryMe;
use perl5:DBI;

Actually, I kinda like that because it gives a logical spot to talk
about how to import a namespace, if you want to modify it. Like what
if you want to alias the namespace:

use namespace :perl5<OldSchoolPerl>;

or some such.

But it's also possible we should do something more sigilistic or
twigilistic for foreign namespace roots. A punishingly dehuffmanized
version might be

use NAMESPACE::perl5::DBI;

which for alphabetic names the parser might allow us to reduce to

use **perl5::DBI;

much like we allow *Foo as short for GLOBAL::Foo.

Larry

Larry Wall

unread,
Jul 6, 2006, 12:27:00 PM7/6/06
to perl6-l...@perl.org
On Thu, Jul 06, 2006 at 09:09:08AM -0700, Larry Wall wrote:
: use **perl5::DBI;

which, if you don't like the two-character form, you can spell:

⁑perl5::DBI

:-)

Hmm, hmm, speaking of sanity, how 'bout user-defined sigils and twigils:

sigil ¢ = Capture;
twigil ¬ = "NOTREALLY::";
¢¬foo; # not really a capture... :)

Larry

Aaron Sherman

unread,
Jul 6, 2006, 3:38:20 PM7/6/06
to Larry Wall, perl6-l...@perl.org
On Thu, 2006-07-06 at 09:09 -0700, Larry Wall wrote:
> On Thu, Jul 06, 2006 at 10:40:21AM -0400, Audrey Tang wrote:
> : The : form is approved and canonical (line 303, the Modules spec, aka
> : S11.pm version 14).
> :
> : use perl5:DBI;
[...]

> : my $dbh = perl5:DBI; # currently parsed as perl5(:DBI)
> :
> : but we can say that for each HLL-qualified module name, it's a single
> : token and is therefore recognized first.
> :
> : Does that sound sane? If yes, S11 can be updated to reflect that.
>
> It's only sane if we require the predeclaration of the language higher
> in the lexical scope.

Namespaces aren't your only concern here. You also care about all of the
semantics of module loading and the integration of the target language's
module loading semantics with Perl 6's. For example, there's a
completely separate search path for Perl 5 modules, and an implicit
invocation of a package method that might not happen in P6. I think what
you want to be saying is not, "use DBI from the Perl 5 namespace", but
"invoke the Perl 6 / Perl 5 module loader interface for DBI".

That's really something like:

use Lang::Perl5::Loader;
perl5use DBI;

That we provide a shortcut called "use perl5:DBI" is just sugar, and we
might provide that for many languages. However, the user should know how
to do it the "hard way" in case they want to talk to a less officially
blessed language:

use Lang::Bash::Loader;
use Lang::Elisp::Loader;
bashuse "~/.bashrc";
elispuse "hanoi";
say %*ENV{PATH}
hanoi(13);

Inventing syntactic sugar for the back-end case probably doesn't buy you
anything special.

--
Aaron Sherman <a...@ajs.com>
Senior Systems Engineer and Toolsmith
"We had some good machines, but they don't work no more." -Shriekback


0 new messages