Am 18.08.2010 01:33, schrieb Darren Duncan:
David H. Adler wrote:
Hm. So how are valid parameter names defined? Identifiers in perl6 seem
to be composed of letters, digits and underscores (and hyphens and
apostrophes between letters).

That's correct.

Are parameter names defined differently?

Yes and no. If you want to use the normal syntax like this:

sub f(:$named-name) { ... }

your indeed limited to identifiers. But with slurpy hashes you can use any key, really:

sub f(*%h) {
   say %h{ '++' };
}
f(|{ '++' => 'non-identifier names work'})

However this is rather clumsy, and should be reserved for interoperation with other languages which have different ideas of what an identifier is.

You certainly seem to be able to declare a variable $1.

If Rakudo allows that, it's a bug. STD.pm6, Larry's Perl 6 grammar, says
"Can't declare a numeric variable" about it.

I believe that Perl 6 identifiers can be any string at all, but that
then they have to appear quoted in the general case;
the above
restriction just refers to the common case of unquoted identifiers. This
said, I'm not sure yet what the syntax is for quoting identifiers. --

This distinction is new to me. For "identifier" means what you call "unquoted identifier", and my reading of the synopsis so far hasn't contradicted that unerstanding in any way.

But that's really a question of how you call stuff - your explanation is correct, as I demonstrated above.

Cheers,
Moritz

Reply via email to