develooper Front page | perl.perl6.language | Postings from October 2001

Re: Perl 6 Object Oriented Operators [was: Perl 6 - Cheerleaders?]

From:
Damian Conway
Date:
October 30, 2001 14:40
Subject:
Re: Perl 6 Object Oriented Operators [was: Perl 6 - Cheerleaders?]
Message ID:
200110302240.JAA27949@indy05.csse.monash.edu.au

   > > 		method foo ( $me, $again : $big, $boy ) {...}
   > > 
   > > should be able to be called via either of:
   > > 
   > > 		foo $obj1, $obj2 : @args;
   > > or:
   > > 		($obj1, $obj2).foo(@args);
   > 
   > 
   > This stuff brings to mind all sorts of questions:
   > 
   > * If foo() is declared as above, what values do $me and $again have when
   >   the method is called as $obj.foo(@args);? Is $again undef?

I would assume it's an error. foo() expects two arguments before the
(implicit) colon, but you gave it only one.


   > * What happens when foo is declared as "method foo ($a: *@_) { ... }"
   >   and called as "foo $a, $b: @args;"? Is $b ignored?

Error. Expected one invocant but found two.


   > * Would "foo $a, $b ^: @args" work as "($a,$b)^.foo(@args)"?

No. The ^ is on the method call, not on the colon.

BTW, colon isn't an operator (it's a separator), so it can't be hyped.


   > * Would (($o1,$o2),($o3,$o4))^.foo(@args); be the same as
   >   ($o1,$o2).foo(@args); ($o3,$o4).foo(@args); ?

Almost. It would actually be the same as:

       ( ($o1,$o2).foo(@args), ($o3,$o4).foo(@args) )

though the difference is trivial in a void context.


   > * "method foo ($a, $b: *@_) { ... }; foo $o1, $o2: @args;" seems like a
   >   binding that doesn't mention :=. i.e., ($a,$b) := ($o1,$o2);
   
*All* argument passing to method and subroutine calls is done via
binding (even in Perl 5). Read back over my posts and you'll see that
I always express argument passing in terms like: "the first argument
is bound to the $x parameter".
   ^^^^^


   > Will there be other "hidden" uses of the := operator?

The other implicit binding is also the same as in Perl 5.
Namely: the iteration variable (or $_) in a C<foreach>.

Damian



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About