On Mon, Aug 16, 2010 at 03:49:52PM -0400, Will Coleda wrote:
> On Mon, Aug 16, 2010 at 3:36 PM, David H. Adler <d...@panix.com> wrote:
> > On Mon, Aug 16, 2010 at 03:14:28PM -0400, Will Coleda wrote:
> >> On Mon, Aug 16, 2010 at 3:03 PM, David H. Adler <d...@panix.com> wrote:
> >> > Given the code:
> >> >
> >> > ? ? ? ?use v6;
> >> >
> >> > ? ? ? ?sub speakhash (*%hash) {
> >> > ? ? ? ? ? ?say "%hash{}";
> >> > ? ? ? ?}
> >> >
> >> > ? ? ? ?speakhash(1, 2, 3, 4, 5, 6);
> >> >
> >> > I get the error:
> >> >
> >> > ? ? ? ?Too many positional parameters passed; got 6 but expected 0
> >> > ? ? ? ? ?in 'speakhash' at line 3:slurphash.p6
> >> > ? ? ? ? ? ?in main program body at line 7:slurphash.p6
> >> >
> >> > According to the UsingPerl6 draft document, "*%hash slurps all the
> >> > remaining unbound named arguments into a hash."
> >>
> >> The key here is "named" arguments; You've invoked the speakhash sub
> >> with positional args.
> >>
> >> Try this:
> >>
> >> ?sub speakhash (*%hash) {
> >> ? ? ?say %hash.perl;
> >> ?}
> >>
> >> ?speakhash(a => 1, b => 2, c => 3, d => 4, e => 5, f => 6);
> >
> > Hm. It just so happens that I tried speakhash(1 => 2, 3 => 4, 5 => 6)
> > and that didn't work. It seems that, although one can create a hash with
> > those pairs, you *can't* pass them as arguments. I'm not clear why.
> >
> > dha
> >
> > --
> 
> I believe named arguments have to be valid parameter names.

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). Are parameter names defined differently?
You certainly seem to be able to declare a variable $1.

dha

-- 
David H. Adler - <d...@panix.com> - http://www.panix.com/~dha/
I'm Doug Stanhope and that's why I drink.
        - Doug Stanhope

Reply via email to