namespaces, a single colon to separate HLL prefix?

2006-07-06 Thread Allison Randal
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


Re: namespaces, a single colon to separate HLL prefix?

2006-07-06 Thread Audrey Tang


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

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.}

--


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
Description: This is a digitally signed message part


sprintf for S29

2006-07-06 Thread Aaron Sherman
I've taken a stab at sprintf for S29. All I've done differently from
Perl 5 is to drop %p and %n (generates an exception) and add %C
(closure) to replace the functionality of %n. Are there any additional
formats that we want to add?

Other than that, this should be exactly the same as Perl 5:

=item sprintf

 our method Str Str::sprintf ( Str $format: [EMAIL PROTECTED] )
 our multi Str sprintf ( Str $format, [EMAIL PROTECTED] )

This function is mostly identical to the C library sprintf function.

The C$format is scanned for C% characters. Any C% introduces a
format token. Format tokens have the following grammar:

 grammar Str::SprintfFormat {
  rule format_token { \%: index? precision? modifier? directive }
  rule index { \d+ \$ }
  rule precision { flags? vector? precision_count }
  rule flags { [\ +0\#\-]+ }
  rule precision_count { [ [1-9]\d* | \* ]? [ \. [ \d* | \* ] ]? }
  rule vector { \*? v }
  rule modifier { [lhVqL] | ll }
  rule directive { [\%csduoxefgXEGbpniDUOF] }
 }

Directives guide the use (if any) of the arguments. When a directive
(other than C%) are used, they indicate how the next argument
passed is to be formatted into the string.

The directives are:

 %   a percent sign
 c   a character with the given number
 s   a string
 d   a signed integer, in decimal
 u   an unsigned integer, in decimal
 o   an unsigned integer, in octal
 x   an unsigned integer, in hexadecimal
 e   a floating-point number, in scientific notation
 f   a floating-point number, in fixed decimal notation
 g   a floating-point number, in %e or %f notation
 X   like x, but using upper-case letters
 E   like e, but using an upper-case E
 G   like g, but with an upper-case E (if applicable)
 b   an unsigned integer, in binary
 C   special: invokes the arg as code, see below

Compatibility:

 i   a synonym for %d
 D   a synonym for %ld
 U   a synonym for %lu
 O   a synonym for %lo
 F   a synonym for %f

Perl 5 compatibility:

 n   produces a runtime exception (see below)
 p   produces a runtime exception

The special format directive, C%C invokes the target argument as
code, passing it the result string that has been generated thus
far and the argument array.

Here's an example of its use:

 sprintf %d%C is %d digits long,
$num,
sub($s,@args is rw) [EMAIL PROTECTED],
0;

The special directive, C%n does not work in Perl 6 because of the
difference in parameter passing conventions, but the example above
simulates its effect using C%C.

=cut

-- 
Aaron Sherman [EMAIL PROTECTED]
Senior Systems Engineer and Toolsmith
We had some good machines, but they don't work no more. -Shriekback




Re: namespaces, a single colon to separate HLL prefix?

2006-07-06 Thread Larry Wall
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 :perl5OldSchoolPerl;

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


Re: namespaces, a single colon to separate HLL prefix?

2006-07-06 Thread Larry Wall
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


Re: namespaces, a single colon to separate HLL prefix?

2006-07-06 Thread Aaron Sherman
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 [EMAIL PROTECTED]
Senior Systems Engineer and Toolsmith
We had some good machines, but they don't work no more. -Shriekback