Re: Apo 12: Space in method calls

2004-04-19 Thread Larry Wall
On Sat, Apr 17, 2004 at 01:07:44PM -0500, Abhijit A. Mahabal wrote:
: I do not understand one of the examples in the Use of methods/the dot
: notation section:
: 
: $obj.method ($x + $y) + $z
: 
: From the earlier examples (like $obj.method +1), I got the impression that
: you look ahead until you find a term or an operator. In the example above,
: isn't ($x + $y) a full term, all by itself, and in that case would not
: this mean ($obj.method($x + $y)) + $z, the same as the other call it is
: contrasted with:
: 
: $obj.method($x + $y) + $z
: 
: What am I missing?

The distinction is not term/operator exactly.  It's a four-way distinction
between

definitely a postfix op - () hold arguments, otherwise no arguments
definitely a binary op  - there are no arguments
ambiguous   - require disambiguation
definitely a term   - treat method as list operator

where the last category assumes that the term indicates the first item
in an expression.  (Note that a definite unary operator is the beginning
of a term.)

The basic underlying motivation is to allow methods a list operators:

$my.for 1..3 {...}

Now, we haven't actually defined what puts the method call into which
category.  But the rather obvious poler opposites are

$obj.meth,  - obviously not arguments
$obj.meth $foo,$bar - obviously arguments

If the rules get skewed one way or the other to eliminate the ambiguos
middle category, I'd say that we tend to give the benefit of the
doubt to the list, and you have to put a stopper like comma or a
right bracket or brace, or put explicit empty parens, if you want to
pass no arguments.  But if we can unambiguously define what's ambiguous :-)
then it might be useful to force people to clarify what they mean, just
for readability.

Larry


Re: Apo 12: Space in method calls

2004-04-19 Thread Abhijit A. Mahabal

On Mon, 19 Apr 2004, Larry Wall wrote:

 On Sat, Apr 17, 2004 at 01:07:44PM -0500, Abhijit A. Mahabal wrote:
 : $obj.method ($x + $y) + $z
 :
 : From the earlier examples (like $obj.method +1), I got the impression that
 : you look ahead until you find a term or an operator. In the example above,
 : isn't ($x + $y) a full term, all by itself, and in that case would not

 : What am I missing?

 The distinction is not term/operator exactly.  It's a four-way distinction
 between

 definitely a postfix op   - () hold arguments, otherwise no arguments
 definitely a binary op- there are no arguments
 ambiguous - require disambiguation
 definitely a term - treat method as list operator

 where the last category assumes that the term indicates the first item
 in an expression.  (Note that a definite unary operator is the beginning
 of a term.)

 $obj.meth,- obviously not arguments
 $obj.meth $foo,$bar   - obviously arguments


 $obj.meth() + $bat - obviosly not arguments
 $obj.meth () + $bat- obviosly not arguments
 $obj.meth ($foo + $bar) + $bat - ambiguous, likely to be list
 $obj.meth($foo + $bar) + $bat  - $foo + $bar the argument
 $obj.meth($foo + $bar), $bat   - list

Is that about the story so far? Or is the last example probably going to
be illegal without a space?

How bad is it to require space before arguments that are a list, so that
the no-space case is unambiguous?

 Larry

--Abhijit



Re: Apo 12: Space in method calls

2004-04-19 Thread Larry Wall
On Mon, Apr 19, 2004 at 10:37:57AM -0500, Abhijit A. Mahabal wrote:
:  $obj.meth,  - obviously not arguments
:  $obj.meth $foo,$bar - obviously arguments
: 
: 
:  $obj.meth() + $bat - obviosly not arguments
:  $obj.meth () + $bat- obviosly not arguments

No, obviously arguments.  Okay, I see the problem.  What you're missing
is that in an earlier Apocalypse, we said that postfix subscripts
and argument lists may not have an intervening space.

:  $obj.meth ($foo + $bar) + $bat - ambiguous, likely to be list

No, obviously arguments.

:  $obj.meth($foo + $bar) + $bat  - $foo + $bar the argument

Correct.

:  $obj.meth($foo + $bar), $bat   - list

No, if you mean that $bat is the final argument to the method call.
Yes, if by that you mean the list is outside the method call.  The
absence of a space makes ($foo + $bar) a postfix argument-supplying
operator.  So this is parsed:

($obj.meth($foo + $bar)), $bat

: Is that about the story so far? Or is the last example probably going to
: be illegal without a space?

It's certainly not illegal, but it won't do what you want if you think
it'll pass $pat to $obj.meth.

: How bad is it to require space before arguments that are a list, so that
: the no-space case is unambiguous?

It may turn out that all the unambiguous cases do in fact require space
before the list (unless you use the explicit colon).  However, that doesn't
necessarily make it beneficial to declare that

$obj.meth+1

is unambiguous in the other direction.  I think if something is going
to be unclear to the *reader* of the code, we should probably not
make it easy to write it that way.

Larry


Re: Apo 12: Space in method calls

2004-04-19 Thread Abhijit A. Mahabal
 No, obviously arguments.  Okay, I see the problem.  What you're missing
 is that in an earlier Apocalypse, we said that postfix subscripts
 and argument lists may not have an intervening space.

Oh, I see. Yes, I had missed that. Thanks for clearing that up.

--Abhijit


Apo 12: Space in method calls

2004-04-17 Thread Abhijit A. Mahabal
I do not understand one of the examples in the Use of methods/the dot
notation section:

$obj.method ($x + $y) + $z

From the earlier examples (like $obj.method +1), I got the impression that
you look ahead until you find a term or an operator. In the example above,
isn't ($x + $y) a full term, all by itself, and in that case would not
this mean ($obj.method($x + $y)) + $z, the same as the other call it is
contrasted with:

$obj.method($x + $y) + $z

What am I missing?

--Abhijit

Abhijit A. Mahabal  http://www.cs.indiana.edu/~amahabal/