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

Re: Perl 6 - Cheerleaders?

Thread Previous | Thread Next
From:
Aaron Sherman
Date:
October 26, 2001 10:13
Subject:
Re: Perl 6 - Cheerleaders?
Message ID:
20011026131341.C13441@ajs.com
On Thu, Oct 25, 2001 at 04:53:46PM -0500, Garrett Goebel wrote:
> Piers Cawley has written a nice article entitled: "Perl 6 : Not Just For
> Damians".

I had missed what unary . really did, and this explained it to me. I'm
now much more excited about it as a "with"-like operator.

It does make me think, though... Would it make sense to have an
accessor operator? For example, in Perl5 I would do this:

	sub foo {
		my $self = shift;
		my $old = $self->{foo};
		# So $obj->foo(undef) will work
		if (@_) {
			$self->{foo} = shift @_;
		}
		return $old;
	}

In Perl6 with the unary ., that becomes:

	sub .foo (*@args) {
		my $old = $.{foo};
		# So $obj.foo(undef) will work
		$.{foo} = shift @args if @args;
		return $old;
	}

So, since this is likely to be fairly common, could we perhaps have
a shortcut?

	sub .{foo} () {}

Of course, this is the simple case. In reality, the transformation
would be:

	sub .{NAME} () BLOCK

which becomes

	sub .NAME (*@args) {
		BLOCK
		my $old = $.{NAME};
		$.{foo} = shift @args if @args;
		return $old;
	}

The syntax might not be wise. I dunno how I feel about YAUB
(Yet Another Use of Braces). Perhaps some syntax like:

	accessor .NAME () BLOCK

But the .{method} syntax does seem to be a very ovious meaning, given
what .{NAME} is going to mean inside of the method.

Then again, we could call it all quits and come up with a naming
convention that allows some members to be automatically exported
as methods, and others to be withheld.

-- 
Aaron Sherman
ajs@ajs.com		finger ajskey@b5.ajs.com for GPG info. Fingerprint:
www.ajs.com/~ajs	6DC1 F67A B9FB 2FBA D04C  619E FC35 5713 2676 CEAF
  "Write your letters in the sand for the day I'll take your hand
   In the land that our grandchildren knew." -Queen/_'39_

Thread Previous | Thread Next


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