develooper Front page | perl.perl6.language | Postings from August 2006

Same-named arguments

Thread Next
Michael Snoyman
August 25, 2006 08:37
Same-named arguments
Message ID:
I asked this same question on perl6-users, but no one really seemed to have
a definitive answer, so please forgive me for reasking.

I was wondering how named arguments would work when parameters of different
types had the same name, ie sub foo($bar, @bar, &bar) {...}.  I wrote a
little script to test it out and ran it through pugs.  Here's the results:


I'm just starting with Perl 6.  I was reading through "Perl 6 and Parrot
Essentials" (finally arrived yesterday from Amazon; very happy) and I was
wondering what would happen if you had a parameter list that included
variables of a different type but the same name (ie, $foo, @foo).  I wrote a
little test script and ran it through pugs.  Here's what I got:


use v6;

sub mysub($foo, @foo, %foo) {
	say "Starting mysub";
	say "Printing scalar";
	say $foo;
	say "Printing array";
	say @foo;
	say "Printing hash";

	say %foo;
	say "Leaving mysub\n";

my $foo = 'foo';
my @foo = qw|foo bar|;
my %foo = ( foo => 'bar', foo2 => 'bar2' );

mysub($foo, @foo, %foo);
mysub(:foo($foo), :foo(@foo), :foo(%foo));


Starting mysub
Printing scalar
Printing array
Printing hash
foo barfoo2 bar2
Leaving mysub

Starting mysub
Printing scalar
Printing array

Printing hash

Leaving mysub

Just wondering if the language is meant to work that way, or if it's a pugs


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About