Legal in perl5:
my $foo = foo( 1 ); # A
my $foo = foo(1); # B
my $foo = foo (1); # C
my $foo = foo ( 1 # D
);
####
my $foo = $object->method (1)
->method (2)
->method (3);
##
##
my $foo = $object.method(1)
.method(2)
.method(3);
##
##
$ cat t.pl
use v6;
class C {
has Int $.x is rw = 0;
method foo (Int $i) { $!x += $i; return self; }
method bar (Int $i) { $!x -= $i; return self; }
}
C.new().foo(1).bar(2).say;
$ perl6 t.pl
C.new(x => -1)
$ cat t.pluse v6;
class C {
has Int $.x is rw = 0;
method foo (Int $i) { $!x += $i; return self; }
method bar (Int $i) { $!x -= $i; return self; }
}
C.new()
.foo(1)
.bar(2)
.say;
$ perl6 t.pl
===SORRY!=== Error while compiling t.pl
Two terms in a row
at t.pl:11
------> ⏏.foo(1)
expecting any of:
infix stopper
infix or meta-infix
statement end
statement modifier
statement modifier loop
##
##
cat t.pl
use v6;
class C {
has Int $.x is rw = 0;
method foo (Int $i) { $!x += $i; return self; }
method bar (Int $i) { $!x -= $i; return self; }
}
C.new()\
.foo(1)\
.bar(2)\
.say;
$ perl6 t.pl
C.new(x => -1)