Nathan Wiger writes: > Paul Seamons wrote: > >>> meth foo { > >>> $_.meth; # defaults to the invocant > >>> .meth; # operates on $_ which defaults to the invocant > >>> $^.meth; # is the invocant > >>> $^1.meth; # is the first invocant > >>> $^2.meth; # is the second invocant > >> > >>I'm starting to get confused at the "need" for all these special > >>variables. I vote that we steal from prior art in numerous other > >>languages and just auto-set $SELF or $THIS or whatever and call it done. > > > > > >The problem is that there is no globally safe name to use that uses > >letters only. Also there is a certain line noise problem (which may not > >really be a problem - but looks like one once we have a more concise > >alternative): > > I understand the purported problem, but what I'm saying is that it > really isn't one. Variables magically coming into existence doesn't seem > to be a problem for any language but Perl 6. Many other languages set > "this" automagically. > > > method foo { > > $SELF.prop = $SELF.meth($SELF.get_foo, $SELF.get_bar); > > $SELF.say("Hello " ~ $SELF.prop); > > } > > I'm not sure the point of this block; it's hardly horrific.
I think it is. It's obviously a matter of taste. But all those $SELFs, in my opinion, really take away from the meaning of the code. I loathe reading such Perl 5 OO code, for precisely the same reason. We already have a shorthand (which is an only-hand in some cases) for accessing attributes: method foo { $.prop = $self.meth($.foo, $.bar); $self.say("Hello $.prop"); } And it seems natural to go for methods too, especially since attributes are allowed just to be fancy methods. I have always wondered what would happen if we blurred the distinction altogether. It's tricky, because you need direct access to implement accessors. But since variables for which accessors are not automatically generated are already marked as $:, perhaps it is an option: class Point { has $.x is rw; has $.y is rw; has Pdl $:coords; method set_coords(Pdl $new) { ($.x, $.y) = ($new  $:coords.inverse  Pdl.new($.x, $.y)).list; $:coords = $new; } method swap_coords() { $.set_coords(Pdl([0, 1; 1, 0])); # calls a method with $. syntax } } Luke