This message pretty much sums up the distributive operator thing. Thought
I'd forward it on. I guess any further discussion of this topic ought to
be on perl6-language unless some has a better idea or doesn't think this
is the right place for it.
- D
<[EMAIL PROTECTED]>
---------- Forwarded message ----------
Date: Mon, 26 Mar 2001 08:16:24 -0600 (CST)
From: David M. Lloyd <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Cc: Perl 5 Porters <[EMAIL PROTECTED]>
Subject: Re: Distributive -> and indirect slices
On Mon, 26 Mar 2001 [EMAIL PROTECTED] wrote:
> > > > My thinking was that not too many people use the current
> > > > behaviour... maybe for Obfuscated Perl contests, but the operator could be
> > > > so much more powerful than it is right now.
> > >
> > > Eh, don't forget it also provides scalar context to 'method' in:
> > >
> > > $obj -> method -> other_method;
> > >
> > > I don't think methods returning objects in scalar context and lists
> > > in list context are obfuscated. That's what's wantarray is about, isn't?
> >
> > That behaviour wouldn't change, since the leftmost expression is a scalar.
>
> Wait, that doesn't make sense.
>
> @a = $obj -> method;
>
> calls method in list context because of the assignment. Now you are
> suggesting that it should call method in scalar context because of '$obj'?
No, I'm suggesting that the behavior shouldn't change becuase of '$obj'.
That is, if the leftmost expression is a scalar, the expression will take
the context that it would currently have under our Perl 5 rules.
However if the leftmost expression is a list, the whole expression should
be in list context because all return items will be flattened into a list,
and it just doesn't make sense to me to have these functions be called in
scalar context. I mean, there'd be no way to specify what you want. Take
these examples:
$a = $obj->method; # Clearly scalar context.
@a = $obj->method; # Clearly list context.
$obj->method; # Clearly void context.
$a = $obj->method1->method2; # Both methods in scalar context.
@a = $obj->method1->method2; # method1 in scalar context, method2 in list context.
$obj->method1->method2; # method1 in scalar context, method2 in void context.
@a = ($obj1, $obj2)->method; # Clearly list context. Results of method
# calls flattened into a list.
$a = ($obj1, $obj2)->method; # Unclear. Calling in scalar context
# gives no benefit, since you will
# still have 2 return values. Maybe call
# methods in list context anyways and
# give the length of the return list?
# Or else return rightmost value.
($obj1, $obj2)->method; # Same deal. Might as well call in list context.
@a = ($obj1, $obj2)->method1->method2;
# More complicated. Call method1 in list context on $obj1 and $obj2.
# Call method2 in list context on each of method1's return values.
# Results flattened into a list, assigned to @a.
$a = ($obj1, $obj2)->method1->method2;
# Unclear context, might as well be list. Call like above, return list
# length or rightmost value, depending on which would be less useless.
($obj1, $obj2)->method1->method2;
# Call like above, return value chucked.
I hope this clarifies.
NOTE: Maybe this discussion should continue on Perl6-language?
- D
<[EMAIL PROTECTED]>