This topic is actually covered, albeit far less in-depth and lumped with an
unrelated change, by Nathan Wiger's RFC 103, just in case you weren't aware.


On Thu, Sep 14, 2000 at 03:57:41AM -0400, Michael G Schwern wrote:
> Methods will be run in scalar context.  A method which returns a single scalar
> is treated normally.  If a list is returned, it should be treated same as
> array interpolation.  The list seperator will be applied.  In effect, the
> deparsing will really work out as follows:
> 
>     print 'Today\'s weather will be '.join($", $weather->temp()).
>           ' degrees and sunny.';
> 
> However if temp() calls wantarray(), the result will be FALSE (scalar).

Ok, this is very confusing.  You're saying the method is called in scalar
context, but then proceed to call it in list context, meanwhile tricking it
into thinking it's scalar context.  Interpolated method calls should behave
the same as every other method call, without extra magic.

The only decision, then, is to decide which context to use; if it deparses
to concatenation then it seems logical to use scalar context.  This also
makes sense in that you can force list context with @{[ $weather->temp ]} if
you really wanted it.


> =head2 Argument passing
> 
> Interpolation should also handle passing arguments to methods in a string:
> 
>     print "Today's weather will be $weather->temp("F") degrees and sunny.";
> 
> This should deparse to:
> 
>     print 'Today\'s weather will be '.$weather->temp("F").
>           ' degrees and sunny.';
> 
> The arguments to the method are considered as normal expressions, thus:
> 
>     print "There is $obj->foo(this => $yar, that => 2 + 2) in my head.";
> 
> deparses as:
> 
>     print 'There is '.$obj->foo(this => $yar, that => 2 + 2). ' in my head.";

Now perl is parsing full statements within strings.  I -really- don't like
this, not only because perl is now reaching into strings to parse yet more,
but also because it's already beginning to look very difficult for me,
personally, to parse.  Not only that, it gives me the heeby-geebies (which
of course means you should all immediately agree with me :).

I'd say keep it simple, allow only simple, non-parenthetical method calls.

    "foo $foo->bar bar"     --> "foo " . $foo->bar . " bar"
    "foo $foo->bar() bar"   --> "foo " . $foo->bar . "() bar"

Granted, it may confuse the newbies, but I think it makes things much easier
on everyone.



> Normally, whitespace is allowed between tokens of a method call.
> 
>     $obj -> bar ("this");
>     
> and
> 
>     $obj->bar("this");
> 
> are equivalent.  Whitespace between the object, '->', method name and opening
> paren should be disallowed when interpolated.  This will avoid many ambiguous
> cases.

This is a good idea, and has precedence (as I just discovered answering
someone's question about it in #Perl as I was writing this email, weird..):

    "$hash -> {'foo'}"      --> "HASH(0x8bbf0b8) -> {k1}"



Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to