Using a colon in a method and function call in Perl 6

I'm wondering which colons are associated with method and function calls in Perl 6. For the record, I use the version of perl6 2015.05-55-gd84bbbc built on the version of MoarVM 2015.05.

I just saw the following in the Perl6 Test spec (S32-io) (I added a comment):

$fh.print: "0123456789A";   # prints '0123456789A' to the file

As far as I can tell, this is equivalent to:

$fh.print("0123456789A");   # prints '0123456789A' to the file

Both of them seem to take a few arguments and fine-tune lists:

$fh.print: "012", "345", "6789A";   # prints '0123456789A' to the file
$fh.print("012", "345", "6789A");   # prints '0123456789A' to the file

my @a = <012 345 6789A>;

$fh.print(@a);   # prints '0123456789A' to the file
$fh.print: @a;   # prints '0123456789A' to the file

There must be some reason to have these two different syntaxes. Is there a reason to use one or the other syntax?

I also noticed that when used as a method, we should use either :or ()with print:

$fh.print(@a);   # Works
$fh.print: @a;   # Works!
$fh.print @a;    # ERROR!

print. : () :

print @a;  # Prints '0123456789A' (no newline, just like Perl 5)
print(@a); # Ditto
print: @a; # Prints '012 345 6789A' followed by a newline (at least in REPL)

print  @a, @a; # Error (Two terms in a row)
print: @a, @a; # Prints '012 345 6789A 012 345 6789A' followed by a newline (in REPL) 

script. :

print @a;

:

print: @a, @a;

:

$fh.print: @a, @a; # Prints '0123456789A0123456789A' to the file

, , . - . , - ?

+3
2

, declutter , . .

print: @a, , , @a. REPL say .

, .


invocant, .

say $*ERR: 'hello world'; # $*ERR.say('hello world')
+6

- - , , . . grep map - -

@measurements.map( { check_accuracy($_); fail "bad value" if $_ < 0 }  );

: , , , , . , , , , "Lone Paren", - , Lone Ranger , , , .

?

, , ;

@measurements.map:  { check_accuracy($_);  fail "bad value" if $_ < 0 }

.
- , , , .

+5

Source: https://habr.com/ru/post/1681484/


All Articles