Call a function: Difference between revisions

Content added Content deleted
No edit summary
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 46: Line 46:
CALL (R15),(X,Y) call MULTPLIC(X,Y)
CALL (R15),(X,Y) call MULTPLIC(X,Y)
ST R0,Z Z=MULTPLIC(X,Y)</lang>
ST R0,Z Z=MULTPLIC(X,Y)</lang>

=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
Line 156: Line 157:
Resultat : -90
Resultat : -90
</pre>
</pre>

=={{header|ActionScript}}==
=={{header|ActionScript}}==


Line 924: Line 926:
int returnValue = MyFunction();
int returnValue = MyFunction();
</lang>
</lang>

=={{header|C++}}==
=={{header|C++}}==
<lang C++>
<lang C++>
Line 1,220: Line 1,223:
<pre>true
<pre>true
false</pre>
false</pre>

=={{header|Déjà Vu}}==
<lang dejavu># all functions used are from the standard library
# calling a function with no arguments:
random-int
# calling a function with a fixed number of arguments:
+ 1 2
# calling a function with optional arguments:
# optional arguments are not really possible as such
# generally differently named functions are used:
sort [ 3 2 1 ]
sort-by @len [ "Hello" "World" "Bob" ]
# calling a function with a variable number of arguments:
# generally with a special terminator value, which one depends
# on the function called
concat( 1 2 3 )
[ 1 2 3 ]
set{ :foo :bar :spam }
# calling a function with named arguments: not possible
# using a function in first-class context within an expression
$ @-- @len # $ is "compose", so the function returned is "one less than the length"
# obtaining the return value of a function
# return values are always pushed on the stack, so you don't need anything special
random-int
# discarding the return value of a function
drop random-int
# method call:
local :do { :nuthin @pass }
do!nuthin
!import!fooModule # same as eva!import :fooModule
# arguments are passed by object-identity, like in Python and Lua
# partial application is not possible, due to the fact that
# a function's arity is a property of its behavior and not
# of its definition</lang>


=={{header|Dragon}}==
=={{header|Dragon}}==
Line 1,343: Line 1,312:
var sub3 = apply(flip(sub), 3)
var sub3 = apply(flip(sub), 3)
x = sub3(9) //x is 6</lang>
x = sub3(9) //x is 6</lang>

=={{header|Déjà Vu}}==
<lang dejavu># all functions used are from the standard library
# calling a function with no arguments:
random-int
# calling a function with a fixed number of arguments:
+ 1 2
# calling a function with optional arguments:
# optional arguments are not really possible as such
# generally differently named functions are used:
sort [ 3 2 1 ]
sort-by @len [ "Hello" "World" "Bob" ]
# calling a function with a variable number of arguments:
# generally with a special terminator value, which one depends
# on the function called
concat( 1 2 3 )
[ 1 2 3 ]
set{ :foo :bar :spam }
# calling a function with named arguments: not possible
# using a function in first-class context within an expression
$ @-- @len # $ is "compose", so the function returned is "one less than the length"
# obtaining the return value of a function
# return values are always pushed on the stack, so you don't need anything special
random-int
# discarding the return value of a function
drop random-int
# method call:
local :do { :nuthin @pass }
do!nuthin
!import!fooModule # same as eva!import :fooModule
# arguments are passed by object-identity, like in Python and Lua
# partial application is not possible, due to the fact that
# a function's arity is a property of its behavior and not
# of its definition</lang>


=={{header|Elena}}==
=={{header|Elena}}==
Line 3,565: Line 3,568:
Most arguments are passed by reference. Some built-in functions accept arguments (e.g., flags) that are not <code>GEN</code>s; these are passed by value or reference depending on their [[C]] type. See the User's Guide to the PARI Library section 5.7.3, "Parser Codes".
Most arguments are passed by reference. Some built-in functions accept arguments (e.g., flags) that are not <code>GEN</code>s; these are passed by value or reference depending on their [[C]] type. See the User's Guide to the PARI Library section 5.7.3, "Parser Codes".


=={{Header|Perl}}==
=={{header|Perl}}==
The most common syntax; simply calls the function foo on the argument(s) provided.
The most common syntax; simply calls the function foo on the argument(s) provided.
<lang perl>foo(); # Call foo on the null list
<lang perl>foo(); # Call foo on the null list
Line 3,579: Line 3,582:
&{$fooref}('foo', 'bar');
&{$fooref}('foo', 'bar');
$fooref->('foo', 'bar');</lang>
$fooref->('foo', 'bar');</lang>

=={{header|Perl 6}}==
===Theory===
Fundamentally, nearly everything you do in Perl 6 is a function call if you look hard enough.
At the lowest level, a function call merely requires a reference to any
kind of invokable object, and a call to its <tt>postcircumfix:&lt;( )&gt;</tt> method.
However, there are various forms of sugar and indirection that you
can use to express these function calls differently. In particular,
operators are all just sugar for function calls.

Calling a function that requires no arguments:

<lang perl6>foo # as list operator
foo() # as function
foo.() # as function, explicit postfix form
$ref() # as object invocation
$ref.() # as object invocation, explicit postfix
&foo() # as object invocation
&foo.() # as object invocation, explicit postfix
::($name)() # as symbolic ref</lang>

Calling a function with exactly one argument:

<lang perl6>foo 1 # as list operator
foo(1) # as named function
foo.(1) # as named function, explicit postfix
$ref(1) # as object invocation (must be hard ref)
$ref.(1) # as object invocation, explicit postfix
1.$foo # as pseudo-method meaning $foo(1) (hard ref only)
1.$foo() # as pseudo-method meaning $foo(1) (hard ref only)
1.&foo # as pseudo-method meaning &foo(1) (is hard foo)
1.&foo() # as pseudo-method meaning &foo(1) (is hard foo)
1.foo # as method via dispatcher
1.foo() # as method via dispatcher
1."$name"() # as method via dispatcher, symbolic
+1 # as operator to prefix:<+> function</lang>

Method calls are included here because they do eventually dispatch to a true
function via a dispatcher. However, the dispatcher in question is not going
to dispatch to the same set of functions that a function call of that name
would invoke. That's why there's a dispatcher, after all. Methods are declared
with a different keyword, <tt>method</tt>, in Perl 6, but all that does is
install the actual function into a metaclass. Once it's there, it's merely
a function that expects its first argument to be the invocant object. Hence we
feel justified in including method call syntax as a form of indirect function call.

Operators like <tt>+</tt> also go through a dispatcher, but in this case it is
multiply dispatched to all lexically scoped candidates for the function. Hence
the candidate list is bound early, and the function itself can be bound early
if the type is known. Perl 6 maintains a clear distinction between early-bound
linguistic constructs that force Perlish semantics, and late-bound OO dispatch
that puts the objects and/or classes in charge of semantics. (In any case, <tt>&foo</tt>,
though being a hard ref to the function named "foo", may actually be a ref to
a dispatcher to a list of candidates that, when called, makes all the candidates behave as a single unit.)

Calling a function with exactly two arguments:

<lang perl6>foo 1,2 # as list operator
foo(1,2) # as named function
foo.(1,2) # as named function, explicit postfix
$ref(1,2) # as object invocation (must be hard ref)
$ref.(1,2) # as object invocation, explicit postfix
1.$foo: 2 # as pseudo-method meaning $foo(1,2) (hard ref only)
1.$foo(2) # as pseudo-method meaning $foo(1,2) (hard ref only)
1.&foo: 2 # as pseudo-method meaning &foo(1,2) (is hard foo)
1.&foo(2) # as pseudo-method meaning &foo(1,2) (is hard foo)
1.foo: 2 # as method via dispatcher
1.foo(2) # as method via dispatcher
1."$name"(2) # as method via dispatcher, symbolic
1 + 2 # as operator to infix:<+> function</lang>

Optional arguments don't look any different from normal arguments.
The optionality is all on the binding end.

Calling a function with a variable number of arguments (varargs):

<lang perl6>foo @args # as list operator
foo(@args) # as named function
foo.(@args) # as named function, explicit postfix
$ref(@args) # as object invocation (must be hard ref)
$ref.(@args) # as object invocation, explicit postfix
1.$foo: @args # as pseudo-method meaning $foo(1,@args) (hard ref)
1.$foo(@args) # as pseudo-method meaning $foo(1,@args) (hard ref)
1.&foo: @args # as pseudo-method meaning &foo(1,@args)
1.&foo(@args) # as pseudo-method meaning &foo(1,@args)
1.foo: @args # as method via dispatcher
1.foo(@args) # as method via dispatcher
1."$name"(@args) # as method via dispatcher, symbolic
@args X @blargs # as list infix operator to infix:<X></lang>
Note: whether a function may actually be called with a variable number of arguments depends entirely
on whether a signature accepts a list at that position in the argument list, but
describing that is not the purpose of this task. Suffice to say that we assume here that the
foo function is declared with a signature of the form (*@params). The calls above might be interpreted as having a single array argument if the signature indicates a normal parameter instead of a variadic one. What you cannot do in Perl 6 (unlike Perl 5) is pass an array as several fixed arguments. By default it must either represent a single argument, or be part of a variadic list. You can force the extra level of argument list interpolation using a prefix <tt>|</tt> however:

<lang perl6>my @args = 1,2,3;
foo(|@args); # equivalent to foo(1,2,3)</lang>

Calling a function with named arguments:

<lang perl6>foo :a, :b(4), :!c, d => "stuff"
foo(:a, :b(4), :!c, d => "stuff")</lang>

...and so on. Operators may also be called with named arguments, but only
colon adverbials are allowed:

<lang perl6>1 + 1 :a :b(4) :!c :d("stuff") # calls infix:<+>(1,1,:a, :b(4), :!c, d => "stuff")</lang>

Using a function in statement context:

<lang perl6>foo(); bar(); baz(); # evaluate for side effects</lang>

Using a function in first class context within an expression:

<lang perl6>1 / find-a-func(1,2,3)(4,5,6) ** 2;</lang>

Obtaining the return value of a function:

<lang perl6>my $result = somefunc(1,2,3) + 2;</lang>

There is no difference between calling builtins and user-defined functions and operators (or
even control stuctures). This was a major design goal of Perl 6, and apart from a very few
low-level primitives, all of Perl 6 can be written in Perl 6.

There is no difference between calling subroutines and functions in Perl 6, other than that
calling a function in void context that has no side effects is likely to get you a "Useless use of..." warning.
And, of course, the fact that pure functions can participate in more optimizations such as constant folding.

By default, arguments are passed readonly, which allows the implementation to decide whether pass-by-reference or pass-by-value is more efficient on a case-by-case basis. Explicit lvalue, reference, or copy semantics may be requested on a parameter-by-parameter basis, and the entire argument list may be processed raw if that level of control is needed.
===Practice===
Demonstrating each of the above-mentioned function calls with actual running code, along with the various extra definitions required to make them work (in certain cases). Arguments are checked, and function name / run-sequence number are displayed upon success.
<lang perl6>{
state $n;

multi f () { print ' f' ~ ++$n }
multi f ($a) { die if 1 != $a; print ' f' ~ ++$n }
multi f ($a,$b) { die if 3 != $a+$b; print ' f' ~ ++$n }
multi f (@a) { die if @a != [2,3,4]; print ' f' ~ ++$n }
multi f ($a,$b,$c) { die if 2 != $a || 4 != $c; print ' f' ~ ++$n }
sub g ($a,*@b) { die if @b != [2,3,4] || 1 != $a; print ' g' ~ ++$n }

my \i = -> { print ' i' ~ ++$n }
my \l = -> $a { die if 1 != $a; print ' l' ~ ++$n }
my \m = -> $a,$b { die if 1 != $a || 2 != $b; print ' m' ~ ++$n }
my \n = -> @a { die if @a != [2,3,4]; print ' n' ~ ++$n }

Int.^add_method( 'j', method ()
{ die if 1 != self; print ' j' ~ ++$n } );
Int.^add_method( 'k', method ($a)
{ die if 1 != self || 2 != $a; print ' k' ~ ++$n } );
Int.^add_method( 'h', method (@a)
{ die if @a != [2,3,4] || 1 != self; print ' h' ~ ++$n } );

my $ref = &f; # soft ref
my $f := &f; # hard ref
my $g := &g; # hard ref
my $f-sym = '&f'; # symbolic ref
my $g-sym = '&g'; # symbolic ref
my $j-sym = 'j'; # symbolic ref
my $k-sym = 'k'; # symbolic ref
my $h-sym = 'h'; # symbolic ref

# Calling a function with no arguments:

f; # 1 as list operator
f(); # 2 as function
i.(); # 3 as function, explicit postfix form # defined via pointy-block
$ref(); # 4 as object invocation
$ref.(); # 5 as object invocation, explicit postfix
&f(); # 6 as object invocation
&f.(); # 7 as object invocation, explicit postfix
::($f-sym)(); # 8 as symbolic ref

# Calling a function with exactly one argument:

f 1; # 9 as list operator
f(1); # 10 as named function
l.(1); # 11 as named function, explicit postfix # defined via pointy-block
$f(1); # 12 as object invocation (must be hard ref)
$ref.(1); # 13 as object invocation, explicit postfix
1.$f; # 14 as pseudo-method meaning $f(1) (hard ref only)
1.$f(); # 15 as pseudo-method meaning $f(1) (hard ref only)
1.&f; # 16 as pseudo-method meaning &f(1) (is hard f)
1.&f(); # 17 as pseudo-method meaning &f(1) (is hard f)
1.j; # 18 as method via dispatcher # requires custom method, via 'Int.^add_method'
1.j(); # 19 as method via dispatcher
1."$j-sym"(); # 20 as method via dispatcher, symbolic

# Calling a function with exactly two arguments:

f 1,2; # 21 as list operator
f(1,2); # 22 as named function
m.(1,2); # 23 as named function, explicit postfix # defined via pointy-block
$ref(1,2); # 24 as object invocation (must be hard ref)
$ref.(1,2); # 25 as object invocation, explicit postfix
1.$f: 2; # 26 as pseudo-method meaning $f(1,2) (hard ref only)
1.$f(2); # 27 as pseudo-method meaning $f(1,2) (hard ref only)
1.&f: 2; # 28 as pseudo-method meaning &f(1,2) (is hard f)
1.&f(2); # 29 as pseudo-method meaning &f(1,2) (is hard f)
1.k: 2; # 30 as method via dispatcher # requires custom method, via 'Int.^add_method'
1.k(2); # 31 as method via dispatcher
1."$k-sym"(2); # 32 as method via dispatcher, symbolic

# Calling a function with a variable number of arguments (varargs):

my @args = 2,3,4;

f @args; # 33 as list operator
f(@args); # 34 as named function
n.(@args); # 35 as named function, explicit postfix # defined via pointy-block
$ref(@args); # 36 as object invocation (must be hard ref)
$ref.(@args); # 37 as object invocation, explicit postfix
1.$g: @args; # 38 as pseudo-method meaning $f(1,@args) (hard ref)
1.$g(@args); # 39 as pseudo-method meaning $f(1,@args) (hard ref)
1.&g: @args; # 40 as pseudo-method meaning &f(1,@args)
1.&g(@args); # 41 as pseudo-method meaning &f(1,@args)
1.h: @args; # 42 as method via dispatcher # requires custom method, via 'Int.^add_method'
1.h(@args); # 43 as method via dispatcher
1."$h-sym"(@args); # 44 as method via dispatcher, symbolic
f(|@args); # 45 equivalent to f(1,2,3)

}</lang>
{{out}}
<pre>f1 f2 i3 f4 f5 f6 f7 f8 f9 f10 l11 f12 f13 f14 f15 f16 f17 j18 j19 j20 f21 f22 m23 f24 f25 f26 f27 f28 f29 k30 k31 k32 f33 f34 n35 f36 f37 g38 g39 g40 g41 h42 h43 h44 f45</pre>


=={{header|Phix}}==
=={{header|Phix}}==
Line 3,992: Line 3,772:
### Is partial application possible and how
### Is partial application possible and how
# Yes, see http://rosettacode.org/wiki/Partial_function_application#R</lang>
# Yes, see http://rosettacode.org/wiki/Partial_function_application#R</lang>




=={{header|Racket}}==
=={{header|Racket}}==
Line 4,037: Line 3,815:
(λ(x) (foo 1 2 x)) ; a direct way of doing the same
(λ(x) (foo 1 2 x)) ; a direct way of doing the same
</lang>
</lang>

=={{header|Raku}}==
(formerly Perl 6)
===Theory===
Fundamentally, nearly everything you do in Perl 6 is a function call if you look hard enough.
At the lowest level, a function call merely requires a reference to any
kind of invokable object, and a call to its <tt>postcircumfix:&lt;( )&gt;</tt> method.
However, there are various forms of sugar and indirection that you
can use to express these function calls differently. In particular,
operators are all just sugar for function calls.

Calling a function that requires no arguments:

<lang perl6>foo # as list operator
foo() # as function
foo.() # as function, explicit postfix form
$ref() # as object invocation
$ref.() # as object invocation, explicit postfix
&foo() # as object invocation
&foo.() # as object invocation, explicit postfix
::($name)() # as symbolic ref</lang>

Calling a function with exactly one argument:

<lang perl6>foo 1 # as list operator
foo(1) # as named function
foo.(1) # as named function, explicit postfix
$ref(1) # as object invocation (must be hard ref)
$ref.(1) # as object invocation, explicit postfix
1.$foo # as pseudo-method meaning $foo(1) (hard ref only)
1.$foo() # as pseudo-method meaning $foo(1) (hard ref only)
1.&foo # as pseudo-method meaning &foo(1) (is hard foo)
1.&foo() # as pseudo-method meaning &foo(1) (is hard foo)
1.foo # as method via dispatcher
1.foo() # as method via dispatcher
1."$name"() # as method via dispatcher, symbolic
+1 # as operator to prefix:<+> function</lang>

Method calls are included here because they do eventually dispatch to a true
function via a dispatcher. However, the dispatcher in question is not going
to dispatch to the same set of functions that a function call of that name
would invoke. That's why there's a dispatcher, after all. Methods are declared
with a different keyword, <tt>method</tt>, in Perl 6, but all that does is
install the actual function into a metaclass. Once it's there, it's merely
a function that expects its first argument to be the invocant object. Hence we
feel justified in including method call syntax as a form of indirect function call.

Operators like <tt>+</tt> also go through a dispatcher, but in this case it is
multiply dispatched to all lexically scoped candidates for the function. Hence
the candidate list is bound early, and the function itself can be bound early
if the type is known. Perl 6 maintains a clear distinction between early-bound
linguistic constructs that force Perlish semantics, and late-bound OO dispatch
that puts the objects and/or classes in charge of semantics. (In any case, <tt>&foo</tt>,
though being a hard ref to the function named "foo", may actually be a ref to
a dispatcher to a list of candidates that, when called, makes all the candidates behave as a single unit.)

Calling a function with exactly two arguments:

<lang perl6>foo 1,2 # as list operator
foo(1,2) # as named function
foo.(1,2) # as named function, explicit postfix
$ref(1,2) # as object invocation (must be hard ref)
$ref.(1,2) # as object invocation, explicit postfix
1.$foo: 2 # as pseudo-method meaning $foo(1,2) (hard ref only)
1.$foo(2) # as pseudo-method meaning $foo(1,2) (hard ref only)
1.&foo: 2 # as pseudo-method meaning &foo(1,2) (is hard foo)
1.&foo(2) # as pseudo-method meaning &foo(1,2) (is hard foo)
1.foo: 2 # as method via dispatcher
1.foo(2) # as method via dispatcher
1."$name"(2) # as method via dispatcher, symbolic
1 + 2 # as operator to infix:<+> function</lang>

Optional arguments don't look any different from normal arguments.
The optionality is all on the binding end.

Calling a function with a variable number of arguments (varargs):

<lang perl6>foo @args # as list operator
foo(@args) # as named function
foo.(@args) # as named function, explicit postfix
$ref(@args) # as object invocation (must be hard ref)
$ref.(@args) # as object invocation, explicit postfix
1.$foo: @args # as pseudo-method meaning $foo(1,@args) (hard ref)
1.$foo(@args) # as pseudo-method meaning $foo(1,@args) (hard ref)
1.&foo: @args # as pseudo-method meaning &foo(1,@args)
1.&foo(@args) # as pseudo-method meaning &foo(1,@args)
1.foo: @args # as method via dispatcher
1.foo(@args) # as method via dispatcher
1."$name"(@args) # as method via dispatcher, symbolic
@args X @blargs # as list infix operator to infix:<X></lang>
Note: whether a function may actually be called with a variable number of arguments depends entirely
on whether a signature accepts a list at that position in the argument list, but
describing that is not the purpose of this task. Suffice to say that we assume here that the
foo function is declared with a signature of the form (*@params). The calls above might be interpreted as having a single array argument if the signature indicates a normal parameter instead of a variadic one. What you cannot do in Perl 6 (unlike Perl 5) is pass an array as several fixed arguments. By default it must either represent a single argument, or be part of a variadic list. You can force the extra level of argument list interpolation using a prefix <tt>|</tt> however:

<lang perl6>my @args = 1,2,3;
foo(|@args); # equivalent to foo(1,2,3)</lang>

Calling a function with named arguments:

<lang perl6>foo :a, :b(4), :!c, d => "stuff"
foo(:a, :b(4), :!c, d => "stuff")</lang>

...and so on. Operators may also be called with named arguments, but only
colon adverbials are allowed:

<lang perl6>1 + 1 :a :b(4) :!c :d("stuff") # calls infix:<+>(1,1,:a, :b(4), :!c, d => "stuff")</lang>

Using a function in statement context:

<lang perl6>foo(); bar(); baz(); # evaluate for side effects</lang>

Using a function in first class context within an expression:

<lang perl6>1 / find-a-func(1,2,3)(4,5,6) ** 2;</lang>

Obtaining the return value of a function:

<lang perl6>my $result = somefunc(1,2,3) + 2;</lang>

There is no difference between calling builtins and user-defined functions and operators (or
even control stuctures). This was a major design goal of Perl 6, and apart from a very few
low-level primitives, all of Perl 6 can be written in Perl 6.

There is no difference between calling subroutines and functions in Perl 6, other than that
calling a function in void context that has no side effects is likely to get you a "Useless use of..." warning.
And, of course, the fact that pure functions can participate in more optimizations such as constant folding.

By default, arguments are passed readonly, which allows the implementation to decide whether pass-by-reference or pass-by-value is more efficient on a case-by-case basis. Explicit lvalue, reference, or copy semantics may be requested on a parameter-by-parameter basis, and the entire argument list may be processed raw if that level of control is needed.
===Practice===
Demonstrating each of the above-mentioned function calls with actual running code, along with the various extra definitions required to make them work (in certain cases). Arguments are checked, and function name / run-sequence number are displayed upon success.
<lang perl6>{
state $n;

multi f () { print ' f' ~ ++$n }
multi f ($a) { die if 1 != $a; print ' f' ~ ++$n }
multi f ($a,$b) { die if 3 != $a+$b; print ' f' ~ ++$n }
multi f (@a) { die if @a != [2,3,4]; print ' f' ~ ++$n }
multi f ($a,$b,$c) { die if 2 != $a || 4 != $c; print ' f' ~ ++$n }
sub g ($a,*@b) { die if @b != [2,3,4] || 1 != $a; print ' g' ~ ++$n }

my \i = -> { print ' i' ~ ++$n }
my \l = -> $a { die if 1 != $a; print ' l' ~ ++$n }
my \m = -> $a,$b { die if 1 != $a || 2 != $b; print ' m' ~ ++$n }
my \n = -> @a { die if @a != [2,3,4]; print ' n' ~ ++$n }

Int.^add_method( 'j', method ()
{ die if 1 != self; print ' j' ~ ++$n } );
Int.^add_method( 'k', method ($a)
{ die if 1 != self || 2 != $a; print ' k' ~ ++$n } );
Int.^add_method( 'h', method (@a)
{ die if @a != [2,3,4] || 1 != self; print ' h' ~ ++$n } );

my $ref = &f; # soft ref
my $f := &f; # hard ref
my $g := &g; # hard ref
my $f-sym = '&f'; # symbolic ref
my $g-sym = '&g'; # symbolic ref
my $j-sym = 'j'; # symbolic ref
my $k-sym = 'k'; # symbolic ref
my $h-sym = 'h'; # symbolic ref

# Calling a function with no arguments:

f; # 1 as list operator
f(); # 2 as function
i.(); # 3 as function, explicit postfix form # defined via pointy-block
$ref(); # 4 as object invocation
$ref.(); # 5 as object invocation, explicit postfix
&f(); # 6 as object invocation
&f.(); # 7 as object invocation, explicit postfix
::($f-sym)(); # 8 as symbolic ref

# Calling a function with exactly one argument:

f 1; # 9 as list operator
f(1); # 10 as named function
l.(1); # 11 as named function, explicit postfix # defined via pointy-block
$f(1); # 12 as object invocation (must be hard ref)
$ref.(1); # 13 as object invocation, explicit postfix
1.$f; # 14 as pseudo-method meaning $f(1) (hard ref only)
1.$f(); # 15 as pseudo-method meaning $f(1) (hard ref only)
1.&f; # 16 as pseudo-method meaning &f(1) (is hard f)
1.&f(); # 17 as pseudo-method meaning &f(1) (is hard f)
1.j; # 18 as method via dispatcher # requires custom method, via 'Int.^add_method'
1.j(); # 19 as method via dispatcher
1."$j-sym"(); # 20 as method via dispatcher, symbolic

# Calling a function with exactly two arguments:

f 1,2; # 21 as list operator
f(1,2); # 22 as named function
m.(1,2); # 23 as named function, explicit postfix # defined via pointy-block
$ref(1,2); # 24 as object invocation (must be hard ref)
$ref.(1,2); # 25 as object invocation, explicit postfix
1.$f: 2; # 26 as pseudo-method meaning $f(1,2) (hard ref only)
1.$f(2); # 27 as pseudo-method meaning $f(1,2) (hard ref only)
1.&f: 2; # 28 as pseudo-method meaning &f(1,2) (is hard f)
1.&f(2); # 29 as pseudo-method meaning &f(1,2) (is hard f)
1.k: 2; # 30 as method via dispatcher # requires custom method, via 'Int.^add_method'
1.k(2); # 31 as method via dispatcher
1."$k-sym"(2); # 32 as method via dispatcher, symbolic

# Calling a function with a variable number of arguments (varargs):

my @args = 2,3,4;

f @args; # 33 as list operator
f(@args); # 34 as named function
n.(@args); # 35 as named function, explicit postfix # defined via pointy-block
$ref(@args); # 36 as object invocation (must be hard ref)
$ref.(@args); # 37 as object invocation, explicit postfix
1.$g: @args; # 38 as pseudo-method meaning $f(1,@args) (hard ref)
1.$g(@args); # 39 as pseudo-method meaning $f(1,@args) (hard ref)
1.&g: @args; # 40 as pseudo-method meaning &f(1,@args)
1.&g(@args); # 41 as pseudo-method meaning &f(1,@args)
1.h: @args; # 42 as method via dispatcher # requires custom method, via 'Int.^add_method'
1.h(@args); # 43 as method via dispatcher
1."$h-sym"(@args); # 44 as method via dispatcher, symbolic
f(|@args); # 45 equivalent to f(1,2,3)

}</lang>
{{out}}
<pre>f1 f2 i3 f4 f5 f6 f7 f8 f9 f10 l11 f12 f13 f14 f15 f16 f17 j18 j19 j20 f21 f22 m23 f24 f25 f26 f27 f28 f29 k30 k31 k32 f33 f34 n35 f36 f37 g38 g39 g40 g41 h42 h43 h44 f45</pre>


=={{header|REXX}}==
=={{header|REXX}}==
Line 4,448: Line 4,450:
p "%2d %4s" % [1,"xyz"] #=> " 1 xyz" "%2d %4s".%([1,"xyz"])</lang>
p "%2d %4s" % [1,"xyz"] #=> " 1 xyz" "%2d %4s".%([1,"xyz"])</lang>
::Method call which was displayed in the comment is usable actually.
::Method call which was displayed in the comment is usable actually.

=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>fn main() {
<lang rust>fn main() {
Line 4,736: Line 4,739:
end args
end args
</lang>
</lang>




=={{header|Sidef}}==
=={{header|Sidef}}==
Line 4,986: Line 4,987:
calling a subroutine does not require parentheses
calling a subroutine does not require parentheses
deprecated use of parentheses</pre>
deprecated use of parentheses</pre>

=={{header|WDTE}}==
=={{header|WDTE}}==
<lang wdte>let noargs => + 2 5;
<lang wdte>let noargs => + 2 5;