A question about attribute functions

2004-09-01 Thread Aaron Sherman
How do you declare attribute functions? Specifically, I was thinking
about map and what kind of object it would return, and I stumbled on a
confusing point:

class mapper does iterator {
has .transform;
...
}

Ok, that's fine, but what kind of accessor does it get?

my mapper $x .= new(transform = -{(1,2,3)});
$x.transform()

would imply that you're calling method transform, not invoking the
accessor function which does not have a method signature. Would you have
to do this:

class mapper does iterator {
has Code $transform;
...
}
...
$x.transform.();

?

-- 
 781-324-3772
 [EMAIL PROTECTED]
 http://www.ajs.com/~ajs



Re: A question about attribute functions

2004-09-01 Thread Larry Wall
On Wed, Sep 01, 2004 at 08:02:33AM -0700, Larry Wall wrote:
: That might not work either.  This will, though:
: 
: ($x.transform)();

So will

$x.transform()();

for that matter...

Larry


Re: A question about attribute functions

2004-09-01 Thread Juerd
Larry Wall skribis 2004-09-01  8:02 (-0700):
 : $x.transform.();
 That might not work either.  This will, though:
 ($x.transform)();

This is surprising. Can you please explain why .() won't work? I have
methods return subs quite often, and like that I can just attach -() to
it to make them work for me. 

I dislike parens.  If $object.method.() will really not work, is there a
way to call it without adding parens? Adding parens for someone who
doesn't plan an entire line of code before typing it, means going back
(for me, this is the most important reason for using statement
modifiers; it's not just linguistically pleasing).


Juerd


Re: A question about attribute functions

2004-09-01 Thread Larry Wall
On Wed, Sep 01, 2004 at 07:08:57PM +0200, Juerd wrote:
: Larry Wall skribis 2004-09-01  8:02 (-0700):
:  :   $x.transform.();
:  That might not work either.  This will, though:
:  ($x.transform)();
: 
: This is surprising. Can you please explain why .() won't work? I have
: methods return subs quite often, and like that I can just attach -() to
: it to make them work for me. 

Because in Perl 5, we haven't defined -() to be the long form of
a subscripty ().  But in Perl 6, we have

$a[$x]  $a .[$x]# same thing
$a{$x}  $a .{$x}# same thing
$a($x)  $a .($x)# same thing

That says to me that we also have

$a.b($x)$a.b .($x)  # same thing

In the particular case of an attribute, there are no arguments, so the
parens are optional.  But the fact that they're optional means that if
you do put parens, they belong to the method call, not the returned
value.  (And we have to make them optional rather than mandatorily
missing, since we require the parens to interpolate an attribute
in double-quote context.)

: I dislike parens.  If $object.method.() will really not work, is there a
: way to call it without adding parens? Adding parens for someone who
: doesn't plan an entire line of code before typing it, means going back
: (for me, this is the most important reason for using statement
: modifiers; it's not just linguistically pleasing).

Well, it's still extra parens, but my other solution:

$object.method()()

has the benefit of not forcing you to (horrors!) plan in advance.

I suppose you're one of those clever people who prefer to rewrite
the OS by typing

cat /dev/kmem
[EMAIL PROTECTED]@[EMAIL PROTECTED]@7¥$^@ [EMAIL PROTECTED]@...
^D

:-)

Larry