Functions can be called in a couple ways:
say(1, 2, 3) # 123
say: 1, 2, 3 # (1, 2, 3)
The latter seems to pass a Positional
, b
As Raiph tells you above, say:
is a label. So you didn't say
anything (even though you thought you did) and -- outside use of the REPL -- the compiler will complain that your use of was useless:
say: ; # OUTPUT: «WARNINGS for :Useless use of constant value a b c in sink context (lines 1, 1, 1, 1, 1, 1)»
However, you often can use a :
notation instead of parentheses in method calls. Consider the four routine calls below (two subroutine calls then two method calls):
my @numbers = (33, 77, 49, 11, 34);
say map *.is-prime, @numbers ; # simplest subroutine call syntax
say map( *.is-prime, @numbers ); # same meaning, but delimiting args
say @numbers.map( *.is-prime ) ; # similar, but using .map *method*
say @numbers.map: *.is-prime ; # same, but using : instead of parens
These sentences will all return the same (False False False True False)
.
In general, as you see above with map
, you can use ()
in method calls wherever you would use :
, but the opposite is not true; :
can be used only in method calls.
Use ()
if the arguments need to be delimited precisely, as Raiph comments below.
This answer focuses on the basics. See Raiph's answer for more exhaustive coverage of the precise details of routine call syntax. (As an important example, the meaning of these calls normally changes if there's any spaces between the routine name and the colon (:
) or opening parenthesis ((
)).