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

Reply via email to