Hi,
(sorry for the long delay.)
Juerd <juerd <at> convolution.nl> writes:
> Ingo Blechschmidt skribis 2005-09-19 14:21 (+0000):
> > \(1,2,3); # Reference to a list promoted to an array (!)
> > \(((1,2,3))); # same
>
> Except that it has to be a reference to a reference, because (1,2)
> (in scalar context) already evaluates to a reference, because it can't
> be a pure array.
See my definition of &prefix:<\> below. Parentheses used for grouping
do not change the context.
> Could you think of a formal specification of \ the way you want it,
> that doesn't exist of only examples? What context does it give its
> RHS?
multi prefix:<\> (Item $item) {...}
multi prefix:<\> (@array) {...}
multi prefix:<\> (%hash) {...}
# (The necessary magic needed for dealing with the proposed
# [EMAIL PROTECTED], which would be equivalent to map { \$_ } @array,
# is not included here.)
So:
\$obj; # $obj in item context
[EMAIL PROTECTED]; # @array in Array context (so @array doesn't auto-ref
# to a reference to itself, which would cause the problem
# you mentioned (that [EMAIL PROTECTED] would evaluate to a ref
# pointing to a ref))
\%hash; # analogous
> What do you want , in that comma to do?
sub infix:<,> ([EMAIL PROTECTED] is rw) { @things }
# The "is rw" should refer to the parameters, i.e.
# &infix:<,> returns aliases:
# ($a, $b)[0] = $c; # same as $a = $c
# ($a, $b)[0] =:= $a; # true
So the comma operator supplies list context to its arguments (because
of the slurpy @things) and returns an array. It can't return a list,
because, as you've said, lists aren't real data types.
Because the comma operator supplies list context, (@a, @b) flattens
@a and @b, so it's like @a.concat(@b).
(Of course, there is still the comma operator which separates arguments.
This operator is not the &infix:<,> we talk about, e.g.:
foo(1,2,3); # &infix:<,> *not* called
foo (1,2,3); # same as
foo( (1,2,3) ); # &infix:<,> called
(BTW, is the argument-separator comma operator accessible by a
subroutine, like most other operators are? (I think not.)))
> Are parens in any way special when used with \?
No:
\($obj); # same as
\$obj;
\((($obj))); # same as
\$obj;
\($a, $b); # same as
do {
my @temp = ($a, $b);
[EMAIL PROTECTED];
}
\((($a, $b))); # is really
prefix:<\>(((($a, $b)))); # is really
prefix:<\>( ($a, $b) ); # is really
# (Inner parentheses needed to prevent the comma to be treated
# as the other comma operator which separates arguments.)
prefix:<\>(&infix:<,>($a, $b)); # same as
do {
my @temp = ($a, $b);
[EMAIL PROTECTED];
}
> What is the precedence of \?
The comma operator should bind tighter than \:
\$a, $b # same as
(\$a), $b
BTW, &list ::= &infix:<,>:
($a,); # could be considered ugly
list $a; # same effect, but could be considered not ugly
I hope this mail makes sense :)
--Ingo