Buddha Buck wrote:

My impression was that ~> and <~ were more general than that, and mainly did syntax-rewriting.
You can certainly think of it as syntax rewriting
(though, personally, I don't).

What ~> and <~ do is to (respectively) allow arguments and invocants to
appear in a different position to normal: arguments to the left of the
subroutine/method name, and invocants to the right of the method's
argument list.

So, for subroutine arguments, these are exactly equivalent:

	($arg2, $arg3, $arg4) ~> subname $arg1;
	subname ($arg1, $arg2, $arg3, $arg4);

and for method invocants, these are exactly equivalent:

	method($arg1, $arg2) <~ $invocant;
	$invocant.method($arg1, $arg2);
	method $invocant: $arg1, $arg2;

Notice that, in addition to pipelines, these proposed operators give us
MTOWTDI with respect to ordering of the components of a sub or method call.
That is, Perl 6 subroutines may have prefix and/or postfix argument lists,
and Perl 6 methods may have invocants that are any(prefix, infix, postfix).

Any similarity to Lingua::Romana::Perligata is strictly coincidental.



So (4) above was translated in the parsing stage to be exactly identical to (1), by the following conversions:

# original (4)
@in ~> map { ... } ~> grep { ... } -> @out;

# Fully Parenthesized
(((@in ~> map { ... } ) ~> grep { ... } ) -> @out

# "@a ~> function " becomes " function @a
((map { ... } @in) ~> grep { ... } ) ~> @out

# @a ~> function ===> function @a
(grep { ... } (map { ... } @in)) ~> @out

# @a ~> @b ===> @b = @a
@out = (grep { ... } (map { ... } @in))

# removal of duplicate parenthesis
@out = grep { ... } map { ... } @in
Yes. And the inference that most people seem to have drawn
is that this implies that Perl 6 would still have "stand-alone"
C<map> and C<grep> functions.

However, I suspect the correct inference is that Perl 6 will have
C<map> and C<grep> *multimethods*.


With (2) and (3), the situation is different, because they get syntax-converted into a different form:

# Original (3)
@out <~ grep { ... } <~ map { ... } <~ @in;

# fully parenthesized
@out <- ( grep { ... } <~ ( map { ... } <~ @in));
Correct.


  # function <~ @a  ====> function :@a
No.     method <~ @a  ====> method @a:

  @out <- { grep { ... } <- { map { ... } :@in ));
No. That should be either:

    @out <~ ( grep { ... } <~ ( map @in: { ... } ));

or:

    @out <~ ( grep { ... } <~ ( @in.map({ ... }) ));


  # function <~ @a =====> function :@a
  @out <~ grep { ... } :(map { ... } :@in)
That's:

    @out <~ grep (map @in: { ... }): { ... };

or:

    @out <~ @in.map({ ... }).grep({ ... });


  # @a <~ @b =====> @a = @b
  @out = grep { ... } :(map { ... } :@in)
That's:

    @out = grep (map @in: { ... }): { ... };

or:

    @out = @in.map({ ... }).grep({ ... });



To summarize (and, Piers, you can quote me on this....)

Perl 5 allows you to do:

$object->meth1->meth2->meth3; # Perl5 chained method, L2R

Perl 6 will also allow you to do:

$data ~> sub1 ~> sub2 ~> sub3; # Perl6 chained subs, L2R

Perl 5 allows you to to:

sub3 sub2 sub1 $data; # Perl5 chained subs, R2L

Perl 6 will also allow you to do:

meth3 <~ meth2 <~ meth1 <~ $Xbject # Perl 6 chained methods, R2L

All four syntaxes will be available in Perl 6, modulo the fact that '->' is now spelled '.'

The additional functionality that when the last sub or method in the ~> and <~ is a variable an assigment is done is a convenience issue.
Exactly. Thank-you for summarizing it so well.


(As an aside....

I almost wish that calling a method with an incomplete argument list would return a curried function, because that means that

$data ~> print <~ $filehandle;

would work!)
You'll recall that we did consider those implicit semantics for
currying and decided against them, since they greatly degrade the
compiler's ability to detect accidentally incomplete argument lists.

Besides, since the precedences of ~> and <~ would differ
(<~ binding tighter than ~>), that *would* work:

         $data ~> print <~ $filehandle;

   ===>  ($data ~> (print <~ $filehandle));

   ===>  ($data ~> $filehandle.print);

   ===>  ($filehandle.print($data));


Damian

Reply via email to