Simon Cozens asked:

*Why* do methods need their parens?
Because calls to them are not resolved until run-time and because methods
can be overloaded by signature, so we can't tell at parse time what the
parameter list of the called method will be (i.e. where it will end),
so we can't determine how to parse the arguments.

For example. consider:

	$obj.method $obj.method { closure() } $arg1, obj.method $arg2, $arg3;

Is that:

	$obj.method( $obj.method( { closure() }, arg1, obj.method($arg2, $arg3) ) );

or:

	$obj.method( $obj.method({ closure() }, arg1), obj.method($arg2, $arg3) );

or:

	$obj.method( $obj.method({ closure() }), arg1, obj.method($arg2, $arg3) );

or:

	$obj.method( $obj.method({ closure() }), arg1, obj.method($arg2), $arg3 );

???

*All* of them might be valid interpretations, and *none* of them might be known
to be valid (or even knowable) at the point where the code is parsed.

Throw multimethods into the mix and things get an order of magnitude worse.

Incidentally, the indirect object syntax will suffer from exactly the same problems
in Perl 6.

To solution in both cases is to defer the parameter/argument type checking and
the method dispatch until run-time. That works fine, but only if the compiler
can determine exactly how many arguments to pass to the method call. For that,
it needs either explicit parens, or a default rule.

Perhaps Perl 6 *will* have the default rule. Maybe that each method is passed
as many arguments as possible, working recursively outwards (and right-to-left) in
an expression. That would, for example, mean that:

	$obj.method $obj.method { closure() } $arg1, obj.method $arg2, $arg3;

would always mean:

	$obj.method( $obj.method( { closure() }, arg1, obj.method($arg2, $arg3) ) );

That *might* be okay, except that people are going to be very annoyed if the only
possible valid interpretation was:

	$obj.method( $obj.method({ closure() }, arg1), obj.method($arg2, $arg3) );

and they get a run-time error instead.

For that reason, even if we can solve this puzzle, it might be far kinder
just to enforce parens.

Damian


Reply via email to