Function prototype: Difference between revisions

Content added Content deleted
m (→‎{{header|Diego}}: minor adjustments)
m (syntax highlighting fixup automation)
Line 28: Line 28:
* For a main program, specifications are only necessary if a function call appears in the source before the function definition.
* For a main program, specifications are only necessary if a function call appears in the source before the function definition.
* For a package, specifications must appear as part of the specification(.ads) file, and do not appear in the body file(.adb) (The file extensions apply to Gnat Ada and may not apply to all compilers).
* For a package, specifications must appear as part of the specification(.ads) file, and do not appear in the body file(.adb) (The file extensions apply to Gnat Ada and may not apply to all compilers).
<lang Ada>function noargs return Integer;
<syntaxhighlight lang="ada">function noargs return Integer;
function twoargs (a, b : Integer) return Integer;
function twoargs (a, b : Integer) return Integer;
-- varargs do not exist
-- varargs do not exist
function optionalargs (a, b : Integer := 0) return Integer;
function optionalargs (a, b : Integer := 0) return Integer;
-- all parameters are always named, only calling by name differs
-- all parameters are always named, only calling by name differs
procedure dostuff (a : Integer);</lang>
procedure dostuff (a : Integer);</syntaxhighlight>
Other Prototyping: Since pointers are not generic in Ada, a type must be defined before one can have a pointer to that type, thus for making linked-list type semantics another trivial prototyping exists:
Other Prototyping: Since pointers are not generic in Ada, a type must be defined before one can have a pointer to that type, thus for making linked-list type semantics another trivial prototyping exists:
<lang Ada>type Box; -- tell Ada a box exists (undefined yet)
<syntaxhighlight lang="ada">type Box; -- tell Ada a box exists (undefined yet)
type accBox is access Box; -- define a pointer to a box
type accBox is access Box; -- define a pointer to a box
type Box is record -- later define what a box is
type Box is record -- later define what a box is
next : accBox; -- including that a box holds access to other boxes
next : accBox; -- including that a box holds access to other boxes
end record;</lang>
end record;</syntaxhighlight>
Example of a package specification (i.e. prototype):
Example of a package specification (i.e. prototype):
<lang Ada>package Stack is
<syntaxhighlight lang="ada">package Stack is
procedure Push(Object:Integer);
procedure Push(Object:Integer);
function Pull return Integer;
function Pull return Integer;
end Stack;</lang>
end Stack;</syntaxhighlight>


Example of a package body:
Example of a package body:
<lang Ada>package body Stack is
<syntaxhighlight lang="ada">package body Stack is


procedure Push(Object:Integer) is
procedure Push(Object:Integer) is
Line 59: Line 59:
end;
end;


end Stack;</lang>
end Stack;</syntaxhighlight>


To use the package and function:
To use the package and function:
<lang Ada>with Stack;
<syntaxhighlight lang="ada">with Stack;
procedure Main is
procedure Main is
N:integer:=5;
N:integer:=5;
Line 69: Line 69:
...
...
N := Pull;
N := Pull;
end Main;</lang>
end Main;</syntaxhighlight>


=={{header|Aime}}==
=={{header|Aime}}==
<lang aime>integer f0(void); # No arguments
<syntaxhighlight lang="aime">integer f0(void); # No arguments
void f1(integer, real); # Two arguments
void f1(integer, real); # Two arguments
real f2(...); # Varargs
real f2(...); # Varargs
Line 81: Line 81:
# Two arguments: integer and function returning integer and taking one integer argument
# Two arguments: integer and function returning integer and taking one integer argument
integer f6(integer a, real b); # Parameters names are allowed
integer f6(integer a, real b); # Parameters names are allowed
record f7(void); # Function returning an associative array</lang>
record f7(void); # Function returning an associative array</syntaxhighlight>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
Line 87: Line 87:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.8 algol68g-2.8].}}
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.8 algol68g-2.8].}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
'''File: Function_prototype.a68'''<lang algol68>#!/usr/bin/a68g --script #
'''File: Function_prototype.a68'''<syntaxhighlight lang="algol68">#!/usr/bin/a68g --script #
# -*- coding: utf-8 -*- #
# -*- coding: utf-8 -*- #


Line 123: Line 123:
END COMMENT
END COMMENT


SKIP</lang>
SKIP</syntaxhighlight>


=={{header|Amazing Hopper}}==
=={{header|Amazing Hopper}}==
Line 129: Line 129:
Function prototypes are included in a #PROTO declaration in the header, at the beginning of a HOPPER source file, before the functional code (MAIN :). This is enforced by the HOPPER compiler, to declare pseudo functions.
Function prototypes are included in a #PROTO declaration in the header, at the beginning of a HOPPER source file, before the functional code (MAIN :). This is enforced by the HOPPER compiler, to declare pseudo functions.


<syntaxhighlight lang="amazing hopper">
<lang Amazing Hopper>
#!/usr/bin/hopper
#!/usr/bin/hopper


Line 166: Line 166:


{0}return
{0}return
</syntaxhighlight>
</lang>


=={{header|C}}==
=={{header|C}}==
Line 172: Line 172:
Function prototypes are typically included in a header file at the beginning of a source file prior to functional code. However, this is not enforced by a compiler.
Function prototypes are typically included in a header file at the beginning of a source file prior to functional code. However, this is not enforced by a compiler.


<lang c>int noargs(void); /* Declare a function with no argument that returns an integer */
<syntaxhighlight lang="c">int noargs(void); /* Declare a function with no argument that returns an integer */
int twoargs(int a,int b); /* Declare a function with two arguments that returns an integer */
int twoargs(int a,int b); /* Declare a function with two arguments that returns an integer */
int twoargs(int ,int); /* Parameter names are optional in a prototype definition */
int twoargs(int ,int); /* Parameter names are optional in a prototype definition */
int anyargs(); /* An empty parameter list can be used to declare a function that accepts varargs */
int anyargs(); /* An empty parameter list can be used to declare a function that accepts varargs */
int atleastoneargs(int, ...); /* One mandatory integer argument followed by varargs */</lang>
int atleastoneargs(int, ...); /* One mandatory integer argument followed by varargs */</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
'''Abstract methods'''<br/>
'''Abstract methods'''<br/>
Interfaces and abstract classes can define abstract methods that must be implemented by subclasses.
Interfaces and abstract classes can define abstract methods that must be implemented by subclasses.
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
abstract class Printer
abstract class Printer
{
{
Line 192: Line 192:
Console.WriteLine("Hello world!");
Console.WriteLine("Hello world!");
}
}
}</lang>
}</syntaxhighlight>
'''Delegates'''<br/>
'''Delegates'''<br/>
A delegate is similar to a function pointer. They are multicast: multiple methods can be attached to them.
A delegate is similar to a function pointer. They are multicast: multiple methods can be attached to them.
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
public delegate int IntFunction(int a, int b);
public delegate int IntFunction(int a, int b);


Line 216: Line 216:
Console.WriteLine(func(2, 3)); //prints 5. Both functions are called, but only the last result is kept.
Console.WriteLine(func(2, 3)); //prints 5. Both functions are called, but only the last result is kept.
}
}
}</lang>
}</syntaxhighlight>
'''Partial methods'''<br/>
'''Partial methods'''<br/>
A partial type is a type that is defined in multiple files.<br/>
A partial type is a type that is defined in multiple files.<br/>
Line 224: Line 224:
- The method must return void.<br/>
- The method must return void.<br/>
- No access modifiers are allowed. Partial methods are implicitly private.
- No access modifiers are allowed. Partial methods are implicitly private.
<lang csharp>//file1.cs
<syntaxhighlight lang="csharp">//file1.cs
public partial class Program
public partial class Program
{
{
Line 243: Line 243:
p.Print(); //If the implementation above is not written, the compiler will remove this line.
p.Print(); //If the implementation above is not written, the compiler will remove this line.
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
Function declaration in C++ differs from that in C in some aspect.
Function declaration in C++ differs from that in C in some aspect.


<lang cpp>int noargs(); // Declare a function with no arguments that returns an integer
<syntaxhighlight lang="cpp">int noargs(); // Declare a function with no arguments that returns an integer
int twoargs(int a,int b); // Declare a function with two arguments that returns an integer
int twoargs(int a,int b); // Declare a function with two arguments that returns an integer
int twoargs(int ,int); // Parameter names are optional in a prototype definition
int twoargs(int ,int); // Parameter names are optional in a prototype definition
Line 255: Line 255:
template<typename T> T declval(T); //A function template
template<typename T> T declval(T); //A function template
template<typename ...T> tuple<T...> make_tuple(T...); //Function template using parameter pack (since c++11)
template<typename ...T> tuple<T...> make_tuple(T...); //Function template using parameter pack (since c++11)
</syntaxhighlight>
</lang>


=={{header|Clojure}}==
=={{header|Clojure}}==
If you want to make forward declarations, you can use declare.
If you want to make forward declarations, you can use declare.
<lang clojure>(declare foo)</lang>
<syntaxhighlight lang="clojure">(declare foo)</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
Line 265: Line 265:
Prototypes were introduced in COBOL 2002. In the following examples, <code>PROGRAM-ID</code> and <code>PROGRAM</code> can be replaced with the equivalents for functions and methods. However, in method prototypes the <code>PROTOTYPE</code> clause is not used.
Prototypes were introduced in COBOL 2002. In the following examples, <code>PROGRAM-ID</code> and <code>PROGRAM</code> can be replaced with the equivalents for functions and methods. However, in method prototypes the <code>PROTOTYPE</code> clause is not used.


<lang cobol> *> A subprogram taking no arguments and returning nothing.
<syntaxhighlight lang="cobol"> *> A subprogram taking no arguments and returning nothing.
PROGRAM-ID. no-args PROTOTYPE.
PROGRAM-ID. no-args PROTOTYPE.
END PROGRAM no-args.
END PROGRAM no-args.
Line 303: Line 303:
01 ret PIC S9(9) USAGE COMP-5.
01 ret PIC S9(9) USAGE COMP-5.
PROCEDURE DIVISION USING arg RETURNING ret.
PROCEDURE DIVISION USING arg RETURNING ret.
END PROGRAM foreign-func.</lang>
END PROGRAM foreign-func.</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Line 310: Line 310:
Caveat -- This works with specific implementations of CL. This was tested in SBCL.
Caveat -- This works with specific implementations of CL. This was tested in SBCL.


<lang lisp>
<syntaxhighlight lang="lisp">
(declaim (inline no-args))
(declaim (inline no-args))
(declaim (inline one-arg))
(declaim (inline one-arg))
Line 341: Line 341:


(optional-args 1.0 "example") ;=> "1.0 example"
(optional-args 1.0 "example") ;=> "1.0 example"
</syntaxhighlight>
</lang>


[http://clhs.lisp.se/Body/m_declai.htm More about <code>declaim</code> here]
[http://clhs.lisp.se/Body/m_declai.htm More about <code>declaim</code> here]
Line 347: Line 347:
=={{header|D}}==
=={{header|D}}==
Beside function prototypes similar to the ones available in C (plus templates, D-style varargs), you can define class method prototypes in abstract classes and interfaces. The exact rules for this are best explained by the [//http://dlang.org/interface.html documentation]
Beside function prototypes similar to the ones available in C (plus templates, D-style varargs), you can define class method prototypes in abstract classes and interfaces. The exact rules for this are best explained by the [//http://dlang.org/interface.html documentation]
<lang d>/// Declare a function with no arguments that returns an integer.
<syntaxhighlight lang="d">/// Declare a function with no arguments that returns an integer.
int noArgs();
int noArgs();


Line 393: Line 393:
}
}


void main() {}</lang>
void main() {}</syntaxhighlight>


=={{header|Delphi}}==
=={{header|Delphi}}==
Line 401: Line 401:
See [http://docwiki.embarcadero.com/RADStudio/Sydney/en/Class_and_Record_Helpers_(Delphi) Documentation] for more details.<br>
See [http://docwiki.embarcadero.com/RADStudio/Sydney/en/Class_and_Record_Helpers_(Delphi) Documentation] for more details.<br>


<syntaxhighlight lang="delphi">
<lang Delphi>
program Function_prototype;
program Function_prototype;


Line 522: Line 522:
Readln;
Readln;


end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre> Array: [-1, 1, 2, 3, ]
<pre> Array: [-1, 1, 2, 3, ]
Line 534: Line 534:
{{libheader| System.SysUtils}}
{{libheader| System.SysUtils}}
{{libheader| System.Classes}}
{{libheader| System.Classes}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Function_prototype_class;
program Function_prototype_class;


Line 587: Line 587:
end;
end;
readln;
readln;
end.</lang>
end.</syntaxhighlight>


=={{header|Diego}}==
=={{header|Diego}}==
<lang diego>// A prototype declaration for a function that does not require arguments
<syntaxhighlight lang="diego">// A prototype declaration for a function that does not require arguments


begin_funct(foo); // function as a 'method' with no arguments, no return type
begin_funct(foo); // function as a 'method' with no arguments, no return type
Line 675: Line 675:
for_var(v)_until[numArgsOut]_calc([sum]+=[v]);
for_var(v)_until[numArgsOut]_calc([sum]+=[v]);
[voo]_ret([sum]/[numArgsOut]);
[voo]_ret([sum]/[numArgsOut]);
end_funct[];</lang>
end_funct[];</syntaxhighlight>


=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==
In F#, prototypes are called signatures. Signature files are used to bulk annotate the accessibility of the things within them. If something is in an implementation file but not in the signature file, it is assumed to be private to that file. If it is in the signature file without the <code>internal</code> accessibility modifier, then it is assumed to public, otherwise it is internal to the assembly. For more details, see the [http://msdn.microsoft.com/en-us/library/dd233196.aspx documentation]. Below is an example of the signatures produced for the functions specified in the task (without any accessibility modifiers):
In F#, prototypes are called signatures. Signature files are used to bulk annotate the accessibility of the things within them. If something is in an implementation file but not in the signature file, it is assumed to be private to that file. If it is in the signature file without the <code>internal</code> accessibility modifier, then it is assumed to public, otherwise it is internal to the assembly. For more details, see the [http://msdn.microsoft.com/en-us/library/dd233196.aspx documentation]. Below is an example of the signatures produced for the functions specified in the task (without any accessibility modifiers):
<lang fsharp>// A function taking and returning nothing (unit).
<syntaxhighlight lang="fsharp">// A function taking and returning nothing (unit).
val noArgs : unit -> unit
val noArgs : unit -> unit
// A function taking two integers, and returning an integer.
// A function taking two integers, and returning an integer.
Line 701: Line 701:
//optional arguments must be tupled.
//optional arguments must be tupled.
member OptionalArgs : ?x:int * ?y:int -> int
member OptionalArgs : ?x:int * ?y:int -> int
end</lang>
end</syntaxhighlight>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64


' The position regarding prototypes is broadly similar to that of the C language in that functions,
' The position regarding prototypes is broadly similar to that of the C language in that functions,
Line 740: Line 740:
Private:
Private:
i As Integer
i As Integer
End Type</lang>
End Type</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
Line 746: Line 746:


Function declarations whether with a body or without must be "top level" declarations, that is, after the package clause and outside of any other function. Examples of function delarations without bodies are,
Function declarations whether with a body or without must be "top level" declarations, that is, after the package clause and outside of any other function. Examples of function delarations without bodies are,
<lang go>func a() // function with no arguments
<syntaxhighlight lang="go">func a() // function with no arguments
func b(x, y int) // function with two arguments
func b(x, y int) // function with two arguments
func c(...int) // varargs are called "variadic parameters" in Go.</lang>
func c(...int) // varargs are called "variadic parameters" in Go.</syntaxhighlight>
Go does not directly support optional or named parameters and does not have any concept of procedures or subroutines as distinct from functions.
Go does not directly support optional or named parameters and does not have any concept of procedures or subroutines as distinct from functions.


Line 758: Line 758:
which specifies the datatype of variables and return type. For ex. Consider a function add which takes two
which specifies the datatype of variables and return type. For ex. Consider a function add which takes two
integers and returns their sum. It can be prototyped and declared as :
integers and returns their sum. It can be prototyped and declared as :
<lang haskell>
<syntaxhighlight lang="haskell">
add :: Int -> Int -> Int
add :: Int -> Int -> Int
add x y = x+y
add x y = x+y
</syntaxhighlight>
</lang>


Actually all functions in haskell are functions with just one arguments. Haskell will treat above function as a
Actually all functions in haskell are functions with just one arguments. Haskell will treat above function as a
Line 767: Line 767:
is such that it takes an int and returns an int.
is such that it takes an int and returns an int.
Similarly for any function add which takes 3 integers and adds them the actual prototype will be as follows:
Similarly for any function add which takes 3 integers and adds them the actual prototype will be as follows:
<lang haskell>
<syntaxhighlight lang="haskell">
add :: Int->(Int ->(Int->Int))
add :: Int->(Int ->(Int->Int))
</syntaxhighlight>
</lang>
The one that does not require arguements could just be:
The one that does not require arguements could just be:
<lang haskell>
<syntaxhighlight lang="haskell">
printThis = putStrLn("This is being printed.")
printThis = putStrLn("This is being printed.")
</syntaxhighlight>
</lang>
But haskell would rather consider the function to be of return type IO() in this case.
But haskell would rather consider the function to be of return type IO() in this case.


Two arguments:
Two arguments:
<lang haskell>
<syntaxhighlight lang="haskell">
add :: Int -> Int -> Int
add :: Int -> Int -> Int
add x y = x+y
add x y = x+y
</syntaxhighlight>
</lang>


The same thing can be done using the lambda function as :
The same thing can be done using the lambda function as :
<lang haskell>
<syntaxhighlight lang="haskell">
add :: Int -> Int -> Int
add :: Int -> Int -> Int
add = \x->\y -> x+y
add = \x->\y -> x+y
</syntaxhighlight>
</lang>


Two arguments with unnamed parameters:
Two arguments with unnamed parameters:
<lang haskell>
<syntaxhighlight lang="haskell">
doThis :: Int-> Int-> String
doThis :: Int-> Int-> String
doThis _ _ = "Function with unnamed parameters"
doThis _ _ = "Function with unnamed parameters"
</syntaxhighlight>
</lang>


Function with var args requires creation of type class as per the requirement.
Function with var args requires creation of type class as per the requirement.
Line 798: Line 798:
=={{header|J}}==
=={{header|J}}==
J assumes an unknown name is a verb of infinite rank. Rank determines the frames on which the verb executes. As the demonstration shows, changing the rank, assigning the rank before the verb is used in other definitions affects the result. We could, of course, play other games by changing the unknown name from verb to another part of speech.
J assumes an unknown name is a verb of infinite rank. Rank determines the frames on which the verb executes. As the demonstration shows, changing the rank, assigning the rank before the verb is used in other definitions affects the result. We could, of course, play other games by changing the unknown name from verb to another part of speech.
<lang J> NB. j assumes an unknown name f is a verb of infinite rank
<syntaxhighlight lang="j"> NB. j assumes an unknown name f is a verb of infinite rank
NB. f has infinite ranks
NB. f has infinite ranks
f b. 0
f b. 0
Line 857: Line 857:
0 2 4 6 8
0 2 4 6 8
0 3 6 9 12
0 3 6 9 12
0 4 8 12 16</lang>
0 4 8 12 16</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
=== ES5 ===
=== ES5 ===
JavaScript functions may also be used to define prototype objects
JavaScript functions may also be used to define prototype objects
<syntaxhighlight lang="javascript">
<lang JavaScript>
// A prototype declaration for a function that does not require arguments
// A prototype declaration for a function that does not require arguments
function List() {}
function List() {}
Line 900: Line 900:
l.length; // 2
l.length; // 2


</syntaxhighlight>
</lang>


=== ES6 ===
=== ES6 ===
Class Declarations are used to define prototype objects
Class Declarations are used to define prototype objects
<syntaxhighlight lang="javascript">
<lang JavaScript>
// A prototype declaration for a function that does not require arguments
// A prototype declaration for a function that does not require arguments
class List {
class List {
Line 942: Line 942:
l.pop(); // 15
l.pop(); // 15
l.length; // 2
l.length; // 2
</syntaxhighlight>
</lang>


=={{header|Julia}}==
=={{header|Julia}}==
Julia does not need or use function prototypes in general. Generic functions are further specialized as to argument type and return type during just-in-time compilation if required. However, when interacting with other languages such a C which use function prototypes, Julia can prototype its functions for passing its functions to external languages with the @cfunction macro:
Julia does not need or use function prototypes in general. Generic functions are further specialized as to argument type and return type during just-in-time compilation if required. However, when interacting with other languages such a C which use function prototypes, Julia can prototype its functions for passing its functions to external languages with the @cfunction macro:


<lang julia>julia > function mycompare(a, b)::Cint
<syntaxhighlight lang="julia">julia > function mycompare(a, b)::Cint
(a < b) ? -1 : ((a > b) ? +1 : 0)
(a < b) ? -1 : ((a > b) ? +1 : 0)
end
end
mycompare (generic function with 1 method)
mycompare (generic function with 1 method)
</syntaxhighlight>
</lang>


Using @cfunction to create a prototype for passing this to C's quicksort:
Using @cfunction to create a prototype for passing this to C's quicksort:


<lang julia>julia> mycompare_c = @cfunction(mycompare, Cint, (Ref{Cdouble}, Ref{Cdouble}))
<syntaxhighlight lang="julia">julia> mycompare_c = @cfunction(mycompare, Cint, (Ref{Cdouble}, Ref{Cdouble}))
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
Line 964: Line 964:


Here's an example of this. Note that since Kotlin allows arguments to be passed either by name or position for all functions, there is no separate prototype for this situation. Moreover, since arguments may be passed by name, it is strongly recommended (but not obligatory) that the parameter names for overriding members should be the same as for the functions they override. The compiler will issue a warning if this recommendation is not followed.
Here's an example of this. Note that since Kotlin allows arguments to be passed either by name or position for all functions, there is no separate prototype for this situation. Moreover, since arguments may be passed by name, it is strongly recommended (but not obligatory) that the parameter names for overriding members should be the same as for the functions they override. The compiler will issue a warning if this recommendation is not followed.
<lang scala>// version 1.0.6
<syntaxhighlight lang="scala">// version 1.0.6


interface MyInterface {
interface MyInterface {
Line 998: Line 998:
println(d.roo())
println(d.roo())
println(d.poo)
println(d.poo)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,009: Line 1,009:


=={{header|Lua}}==
=={{header|Lua}}==
<lang Lua>function Func() -- Does not require arguments
<syntaxhighlight lang="lua">function Func() -- Does not require arguments
return 1
return 1
end
end
Line 1,023: Line 1,023:
function Func(a,...) -- One argument followed by varargs
function Func(a,...) -- One argument followed by varargs
return a,{...} -- Returns both arguments, varargs as table
return a,{...} -- Returns both arguments, varargs as table
end</lang>
end</syntaxhighlight>


=={{header|Luck}}==
=={{header|Luck}}==
<lang Luck>function noargs(): int = ? ;;
<syntaxhighlight lang="luck">function noargs(): int = ? ;;
function twoargs(x:int, y:int): int = ? ;;
function twoargs(x:int, y:int): int = ? ;;


Line 1,033: Line 1,033:


function anyargs(xs: ...): int = ? ;;
function anyargs(xs: ...): int = ? ;;
function plusargs(x:int, xs: ...): int = ? ;;</lang>
function plusargs(x:int, xs: ...): int = ? ;;</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
Line 1,041: Line 1,041:
Example of change an inner module using another module with same signature. Module MyBeta {Read x : ... } or Module MyBeta (x) { ... } or Module MyBeta(x) { } is the same.
Example of change an inner module using another module with same signature. Module MyBeta {Read x : ... } or Module MyBeta (x) { ... } or Module MyBeta(x) { } is the same.


<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Check {
Module Check {
Module MyBeta (a) {
Module MyBeta (a) {
Line 1,055: Line 1,055:
}
}
Check
Check
</syntaxhighlight>
</lang>


Signatures needed for Event object. An event object get a list of functions, called as modules, and call every function with same signature. We can provide arguments by reference too. We can define simple functions (without visibility except local and global), or group functions (static groups) with visibility local, global and group level, or we can define local scope functions.
Signatures needed for Event object. An event object get a list of functions, called as modules, and call every function with same signature. We can provide arguments by reference too. We can define simple functions (without visibility except local and global), or group functions (static groups) with visibility local, global and group level, or we can define local scope functions.
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Check {,
Module Check {,
\\ make an event object
\\ make an event object
Line 1,104: Line 1,104:
}
}
Check
Check
</syntaxhighlight>
</lang>


Using a function for local call (module visibility)
Using a function for local call (module visibility)


<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Check {,
Module Check {,
\\ make an event object
\\ make an event object
Line 1,160: Line 1,160:
}
}
Check
Check
</syntaxhighlight>
</lang>


Using a Function in a Group (Groups are the User objects in M2000)
Using a Function in a Group (Groups are the User objects in M2000)


<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Check {,
Module Check {,
\\ make an event object
\\ make an event object
Line 1,215: Line 1,215:
}
}
Check
Check
</syntaxhighlight>
</lang>


=={{header|Nim}}==
=={{header|Nim}}==
Procedure declarations can be used if a proc is to be used before its definition.
Procedure declarations can be used if a proc is to be used before its definition.
<lang nim># Procedure declarations. All are named
<syntaxhighlight lang="nim"># Procedure declarations. All are named
proc noargs(): int
proc noargs(): int
proc twoargs(a, b: int): int
proc twoargs(a, b: int): int
Line 1,235: Line 1,235:
proc twoargs(a, b: int): int = echo "twoargs"
proc twoargs(a, b: int): int = echo "twoargs"
proc anyargs(x: varargs[int]): int = echo "anyargs"
proc anyargs(x: varargs[int]): int = echo "anyargs"
proc optargs(a: int, b = 10): int = echo "optargs"</lang>
proc optargs(a: int, b = 10): int = echo "optargs"</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==


<lang ocaml>(* Usually prototype declarations are put in an interface file,
<syntaxhighlight lang="ocaml">(* Usually prototype declarations are put in an interface file,
a file with .mli filename extension *)
a file with .mli filename extension *)


Line 1,262: Line 1,262:


(* A prototype declaration for a function with polymorphic argument *)
(* A prototype declaration for a function with polymorphic argument *)
val poly_arg : 'a -> unit</lang>
val poly_arg : 'a -> unit</syntaxhighlight>


=={{header|Oforth}}==
=={{header|Oforth}}==


Oforth can only forward declare methods (see Mutual Recursion task). A method can be declared without any class implementation :
Oforth can only forward declare methods (see Mutual Recursion task). A method can be declared without any class implementation :
<lang Oforth>Method new: myMethod</lang>
<syntaxhighlight lang="oforth">Method new: myMethod</syntaxhighlight>


This creates a new method object with name myMethod (or does nothing if this object already exists). It says nothing about method implementations (number of parameters, return value, ...).
This creates a new method object with name myMethod (or does nothing if this object already exists). It says nothing about method implementations (number of parameters, return value, ...).
Line 1,285: Line 1,285:


=={{header|OxygenBasic}}==
=={{header|OxygenBasic}}==
<lang>
<syntaxhighlight lang="text">
'DECLARE FUNCTION' ABBREVIATED TO '!'
'DECLARE FUNCTION' ABBREVIATED TO '!'


Line 1,324: Line 1,324:
end extern ' revert to internal function mode
end extern ' revert to internal function mode


</syntaxhighlight>
</lang>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
Line 1,331: Line 1,331:
PARI uses C prototypes. Additionally, gp2c parser codes are essentially function prototypes. They must be placed in the file called by gp2c, not in a file included by it, and they must appear as a <code>GP;</code> comment. For a function
PARI uses C prototypes. Additionally, gp2c parser codes are essentially function prototypes. They must be placed in the file called by gp2c, not in a file included by it, and they must appear as a <code>GP;</code> comment. For a function


<lang c>long
<syntaxhighlight lang="c">long
foo(GEN a, GEN b)</lang>
foo(GEN a, GEN b)</syntaxhighlight>
which takes two (required) <code>t_INT</code> arguments, returns a small integer (a [[C]] long) and appears as <code>bar</code> to the gp interpreter, the following command would be used:
which takes two (required) <code>t_INT</code> arguments, returns a small integer (a [[C]] long) and appears as <code>bar</code> to the gp interpreter, the following command would be used:
<lang c>/*
<syntaxhighlight lang="c">/*
GP;install("foo","LGG","bar","./filename.gp.so");
GP;install("foo","LGG","bar","./filename.gp.so");
*/</lang>
*/</syntaxhighlight>


If its arguments were optional it could be coded as
If its arguments were optional it could be coded as
<lang c>/*
<syntaxhighlight lang="c">/*
GP;install("foo","LDGDG","bar","./filename.gp.so");
GP;install("foo","LDGDG","bar","./filename.gp.so");
*/</lang>
*/</syntaxhighlight>
although other parser codes are possible; this one sends <code>NULL</code> if the arguments are omitted.
although other parser codes are possible; this one sends <code>NULL</code> if the arguments are omitted.


A code like
A code like
<lang c>/*
<syntaxhighlight lang="c">/*
GP;install("foo","s*","bar","./filename.gp.so");
GP;install("foo","s*","bar","./filename.gp.so");
*/</lang>
*/</syntaxhighlight>
can be used to take a variable (0 or more) number of arguments. Note that the return type in this case is implicitly <code>GEN</code>
can be used to take a variable (0 or more) number of arguments. Note that the return type in this case is implicitly <code>GEN</code>


Line 1,356: Line 1,356:
The perl scripting language allows prototypes to be checked during JIT compilation. Prototypes should be placed before subroutine definitions, declarations, or anonymous subroutines. The sigil [[Special characters#Perl|special symbols]] act as argument type placeholders.
The perl scripting language allows prototypes to be checked during JIT compilation. Prototypes should be placed before subroutine definitions, declarations, or anonymous subroutines. The sigil [[Special characters#Perl|special symbols]] act as argument type placeholders.


<lang perl>sub noargs(); # Declare a function with no arguments
<syntaxhighlight lang="perl">sub noargs(); # Declare a function with no arguments
sub twoargs($$); # Declare a function with two scalar arguments. The two sigils act as argument type placeholders
sub twoargs($$); # Declare a function with two scalar arguments. The two sigils act as argument type placeholders
sub noargs :prototype(); # Using the :attribute syntax instead
sub noargs :prototype(); # Using the :attribute syntax instead
sub twoargs :prototype($$);</lang>
sub twoargs :prototype($$);</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,365: Line 1,365:
Use explicit forward definitions. Optional, unless (for instance) you want to use named parameters in a forward call.<br>
Use explicit forward definitions. Optional, unless (for instance) you want to use named parameters in a forward call.<br>
Should be identical to the actual definition, but preceded by "forward" and with no body.
Should be identical to the actual definition, but preceded by "forward" and with no body.
<!--<lang Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #008080;">forward</span> <span style="color: #008080;">function</span> <span style="color: #000000;">noargs</span><span style="color: #0000FF;">()</span> <span style="color: #000080;font-style:italic;">-- Declare a function with no arguments</span>
<span style="color: #008080;">forward</span> <span style="color: #008080;">function</span> <span style="color: #000000;">noargs</span><span style="color: #0000FF;">()</span> <span style="color: #000080;font-style:italic;">-- Declare a function with no arguments</span>
<span style="color: #008080;">forward</span> <span style="color: #008080;">procedure</span> <span style="color: #000000;">twoargs</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- Declare a procedure with two arguments</span>
<span style="color: #008080;">forward</span> <span style="color: #008080;">procedure</span> <span style="color: #000000;">twoargs</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- Declare a procedure with two arguments</span>
Line 1,371: Line 1,371:
<span style="color: #008080;">forward</span> <span style="color: #008080;">function</span> <span style="color: #000000;">anyargs</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- varargs are [best/often] handled as a (single) sequence in Phix</span>
<span style="color: #008080;">forward</span> <span style="color: #008080;">function</span> <span style="color: #000000;">anyargs</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- varargs are [best/often] handled as a (single) sequence in Phix</span>
<span style="color: #008080;">forward</span> <span style="color: #008080;">function</span> <span style="color: #000000;">atleastonearg</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">...);</span> <span style="color: #000080;font-style:italic;">-- Default makes args optional (== actual defn)</span>
<span style="color: #008080;">forward</span> <span style="color: #008080;">function</span> <span style="color: #000000;">atleastonearg</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">...);</span> <span style="color: #000080;font-style:italic;">-- Default makes args optional (== actual defn)</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
No special syntax is needed on actual or forward function definitions for named parameters, and calls are identical whether still forward or now fully defined.<br>
No special syntax is needed on actual or forward function definitions for named parameters, and calls are identical whether still forward or now fully defined.<br>
Defaults on optional parameters in forward definitions can also be dummy (but type compatible) values should the actual not yet be defined.
Defaults on optional parameters in forward definitions can also be dummy (but type compatible) values should the actual not yet be defined.


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli>
<syntaxhighlight lang="pli">
declare s1 entry;
declare s1 entry;
declare s2 entry (fixed);
declare s2 entry (fixed);
Line 1,384: Line 1,384:
declare f2 entry (float) returns (float);
declare f2 entry (float) returns (float);
declare f3 entry (character(*), character(*)) returns (character (20));
declare f3 entry (character(*), character(*)) returns (character (20));
</syntaxhighlight>
</lang>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
Line 1,400: Line 1,400:


PureBasic does not allow either variable arguments or named parameters.
PureBasic does not allow either variable arguments or named parameters.
<lang purebasic>;Forward procedure declare defined with no arguments and that returns a string
<syntaxhighlight lang="purebasic">;Forward procedure declare defined with no arguments and that returns a string
Declare.s booTwo()
Declare.s booTwo()
;Forward procedure declare defined with two arguments and that returns a float
;Forward procedure declare defined with two arguments and that returns a float
Line 1,477: Line 1,477:
ProcedureReturn (x * y) + m
ProcedureReturn (x * y) + m
EndProcedure
EndProcedure
</syntaxhighlight>
</lang>
Sample output:
Sample output:
<pre>Forward Declared procedures:
<pre>Forward Declared procedures:
Line 1,501: Line 1,501:
For example, the naive recursive Fibonacci function. (Note that the texts in parentheses are stack comments and can be omitted. Their inclusion is good practice. No declaration of parameters or arguments is required in Quackery.)
For example, the naive recursive Fibonacci function. (Note that the texts in parentheses are stack comments and can be omitted. Their inclusion is good practice. No declaration of parameters or arguments is required in Quackery.)


<lang> forward is fibonacci ( n --> n )
<syntaxhighlight lang="text"> forward is fibonacci ( n --> n )


[ dup 2 < if done
[ dup 2 < if done
dup 1 - fibonacci
dup 1 - fibonacci
swap 2 - fibonacci + ] resolves fibonacci ( n --> n )</lang>
swap 2 - fibonacci + ] resolves fibonacci ( n --> n )</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Most of the points are covered in this program
Most of the points are covered in this program
<lang racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket


Line 1,520: Line 1,520:
(define (varargs2 a . args) (void)) ;one obligatory argument and the rest are contained in the list
(define (varargs2 a . args) (void)) ;one obligatory argument and the rest are contained in the list


(define (optional-arg (a 5)) (void)) ;a defaults to 5</lang>
(define (optional-arg (a 5)) (void)) ;a defaults to 5</syntaxhighlight>


<tt>(void)</tt> is a function that returns "nothing", so this are prototypes that do nothing.
<tt>(void)</tt> is a function that returns "nothing", so this are prototypes that do nothing.
Although standard Racket doesn't allow type declarations, it allows contracts, so we can add this to the previous declarations
Although standard Racket doesn't allow type declarations, it allows contracts, so we can add this to the previous declarations
<lang racket>
<syntaxhighlight lang="racket">
(provide (contract-out
(provide (contract-out
[two-args (integer? integer? . -> . any)]))</lang>
[two-args (integer? integer? . -> . any)]))</syntaxhighlight>
then any module that imports the function can only pass integers to two-args.
then any module that imports the function can only pass integers to two-args.


Another way is using the <tt>typed/racket</tt> language, like this
Another way is using the <tt>typed/racket</tt> language, like this
<lang racket>
<syntaxhighlight lang="racket">
#lang typed/racket
#lang typed/racket


(: two-args (Integer Integer -> Any))
(: two-args (Integer Integer -> Any))
(define (two-args a b) (void))</lang>
(define (two-args a b) (void))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
Line 1,543: Line 1,543:


A prototype declaration for a function that does not require arguments (and returns an Int):
A prototype declaration for a function that does not require arguments (and returns an Int):
<lang perl6>sub foo ( --> Int) {...}</lang>
<syntaxhighlight lang="raku" line>sub foo ( --> Int) {...}</syntaxhighlight>


A prototype declaration for a function that requires two arguments.
A prototype declaration for a function that requires two arguments.
Note that we can omit the variable name and just use the sigil in the stub, since we don't need to reference the argument until the actual definition of the routine. Also, unlike in Perl 5, a sigil like <tt>@</tt> defaults to binding a single positional argument.
Note that we can omit the variable name and just use the sigil in the stub, since we don't need to reference the argument until the actual definition of the routine. Also, unlike in Perl 5, a sigil like <tt>@</tt> defaults to binding a single positional argument.
<lang perl6>sub foo (@, $ --> Int) {...}</lang>
<syntaxhighlight lang="raku" line>sub foo (@, $ --> Int) {...}</syntaxhighlight>


A prototype declaration for a function that utilizes varargs after one required argument.
A prototype declaration for a function that utilizes varargs after one required argument.
Note the "slurpy" star turns the <tt>@</tt> sigil into a parameter that accepts all the rest of the positional arguments.
Note the "slurpy" star turns the <tt>@</tt> sigil into a parameter that accepts all the rest of the positional arguments.
<lang perl6>sub foo ($, *@ --> Int) {...}</lang>
<syntaxhighlight lang="raku" line>sub foo ($, *@ --> Int) {...}</syntaxhighlight>


A prototype declaration for a function that utilizes optional arguments after one required argument. Optionality is conferred by either a question mark or a default:
A prototype declaration for a function that utilizes optional arguments after one required argument. Optionality is conferred by either a question mark or a default:
<lang perl6>sub foo ($, $?, $ = 42 --> Int) {...}</lang>
<syntaxhighlight lang="raku" line>sub foo ($, $?, $ = 42 --> Int) {...}</syntaxhighlight>


A prototype declaration for a function that utilizes named parameters:
A prototype declaration for a function that utilizes named parameters:
<lang perl6>sub foo ($, :$faster, :$cheaper --> Int) {...}</lang>
<syntaxhighlight lang="raku" line>sub foo ($, :$faster, :$cheaper --> Int) {...}</syntaxhighlight>


Example of prototype declarations for subroutines or procedures, which in Raku is done simply by noting that nothing is returned:
Example of prototype declarations for subroutines or procedures, which in Raku is done simply by noting that nothing is returned:
<lang perl6>sub foo ($, $ --> Nil) {...}</lang>
<syntaxhighlight lang="raku" line>sub foo ($, $ --> Nil) {...}</syntaxhighlight>


A routine may also slurp up all the named arguments that were not bound earlier in the signature:
A routine may also slurp up all the named arguments that were not bound earlier in the signature:
<lang perl6>sub foo ($, :$option, *% --> Int) {...}</lang>
<syntaxhighlight lang="raku" line>sub foo ($, :$option, *% --> Int) {...}</syntaxhighlight>


A routine may make a named parameter mandatory using exclamation mark. (This is more useful in multi subs than in stubs though.)
A routine may make a named parameter mandatory using exclamation mark. (This is more useful in multi subs than in stubs though.)
<lang perl6>sub foo ($, :$option! --> Int) {...}</lang>
<syntaxhighlight lang="raku" line>sub foo ($, :$option! --> Int) {...}</syntaxhighlight>


A routine may unpack an <tt>Array</tt> automaticly. Here the first element is stored in a scalar and the rest in an <tt>Array</tt>. Other buildin types can be [http://design.raku.org/S06.html#Unpacking_array_parameters unpacked] as well.
A routine may unpack an <tt>Array</tt> automaticly. Here the first element is stored in a scalar and the rest in an <tt>Array</tt>. Other buildin types can be [http://design.raku.org/S06.html#Unpacking_array_parameters unpacked] as well.
<lang perl6>sub foo ([$, @]) {...}</lang>
<syntaxhighlight lang="raku" line>sub foo ([$, @]) {...}</syntaxhighlight>


A routine may ask for a closure parameter to implement higher order functions. Typed or untyped signatures can be supplied.
A routine may ask for a closure parameter to implement higher order functions. Typed or untyped signatures can be supplied.
<lang perl6>sub foo (@, &:(Str --> Int)) {...}</lang>
<syntaxhighlight lang="raku" line>sub foo (@, &:(Str --> Int)) {...}</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
Line 1,604: Line 1,604:
To begin with, we look at the definition provided [http://rosettacode.org/wiki/Function_definition#SNOBOL4 at the relevant task page]:
To begin with, we look at the definition provided [http://rosettacode.org/wiki/Function_definition#SNOBOL4 at the relevant task page]:


<lang snobol4> define('multiply(a,b)') :(mul_end)
<syntaxhighlight lang="snobol4"> define('multiply(a,b)') :(mul_end)
multiply multiply = a * b :(return)
multiply multiply = a * b :(return)
mul_end
mul_end
Line 1,611: Line 1,611:
output = multiply(10.1,12.2)
output = multiply(10.1,12.2)
output = multiply(10,12)
output = multiply(10,12)
end</lang>
end</syntaxhighlight>


The key to this is the <code>define()</code> BIF which declares the actual function and the <code>multiply</code> label which is the entry point to the code that is executed. The key is that SNOBOL4 is an almost militantly unstructured language. There is absolutely nothing special about the <code>multiply</code> entry point that distinguishes it from the target of any other branch target. What happens instead is that the <code>define()</code> BIF associates a certain string pattern--the prototype, in effect--with an entry point. The <code>:(mul_end)</code> piece at the end, in fact, exists because were it not present the body of the <code>multiply</code> "function" would be executed: it is a branch to the label <code>mul_end</code>.
The key to this is the <code>define()</code> BIF which declares the actual function and the <code>multiply</code> label which is the entry point to the code that is executed. The key is that SNOBOL4 is an almost militantly unstructured language. There is absolutely nothing special about the <code>multiply</code> entry point that distinguishes it from the target of any other branch target. What happens instead is that the <code>define()</code> BIF associates a certain string pattern--the prototype, in effect--with an entry point. The <code>:(mul_end)</code> piece at the end, in fact, exists because were it not present the body of the <code>multiply</code> "function" would be executed: it is a branch to the label <code>mul_end</code>.
Line 1,621: Line 1,621:
Of course this implies that you can separate the two pieces. Which you can, like this:
Of course this implies that you can separate the two pieces. Which you can, like this:


<lang snobol4> define('multiply(a,b)')
<syntaxhighlight lang="snobol4"> define('multiply(a,b)')


*
*
Line 1,641: Line 1,641:
output = multiply(10.1,12.2)
output = multiply(10.1,12.2)
output = multiply(10,12)
output = multiply(10,12)
end</lang>
end</syntaxhighlight>


With this structure the "function" is declared at the program, the implementation is somewhere down in the middle, and the mainline (<code>test</code> here) is at the end.
With this structure the "function" is declared at the program, the implementation is somewhere down in the middle, and the mainline (<code>test</code> here) is at the end.
Line 1,656: Line 1,656:
Thus a highly-contrived example function that illustrates all of these would look like this:
Thus a highly-contrived example function that illustrates all of these would look like this:


<lang snobol4> define('multiply(a,b)acc1,acc2','mult_impl') :(mult_end)
<syntaxhighlight lang="snobol4"> define('multiply(a,b)acc1,acc2','mult_impl') :(mult_end)
mult_impl acc1 = a
mult_impl acc1 = a
acc2 = b
acc2 = b
Line 1,665: Line 1,665:
output = multiply(10.1,12.2)
output = multiply(10.1,12.2)
output = multiply(10,12)
output = multiply(10,12)
end</lang>
end</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
Line 1,675: Line 1,675:


In the following example, the 'factorial' function is recursive and so needs a forward declaration. However, even though the function takes a single argument, no prior information about that is needed or possible. There is an example of mutual recursion protoyping in the [[Mutual_recursion#Wren]] task.
In the following example, the 'factorial' function is recursive and so needs a forward declaration. However, even though the function takes a single argument, no prior information about that is needed or possible. There is an example of mutual recursion protoyping in the [[Mutual_recursion#Wren]] task.
<lang ecmascript>var factorial // forward declaration
<syntaxhighlight lang="ecmascript">var factorial // forward declaration


factorial = Fn.new { |n| (n <= 1) ? 1 : factorial.call(n-1) * n }
factorial = Fn.new { |n| (n <= 1) ? 1 : factorial.call(n-1) * n }


System.print(factorial.call(5))</lang>
System.print(factorial.call(5))</syntaxhighlight>


{{out}}
{{out}}
Line 1,688: Line 1,688:
=={{header|zkl}}==
=={{header|zkl}}==
In zkl, all functions are var args. Prototypes provide some documentation and an overlay on the incoming args. Named parameters are not supported.
In zkl, all functions are var args. Prototypes provide some documentation and an overlay on the incoming args. Named parameters are not supported.
<lang zkl>fcn{"Hello World"} // no expected args
<syntaxhighlight lang="zkl">fcn{"Hello World"} // no expected args
fcn(){"Hello World"} // ditto
fcn(){"Hello World"} // ditto


Line 1,711: Line 1,711:


// no type enforcement but you can give a hint to the compiler
// no type enforcement but you can give a hint to the compiler
fcn([Int]n){n.sin()} //--> syntax error as Ints don't do sin</lang>
fcn([Int]n){n.sin()} //--> syntax error as Ints don't do sin</syntaxhighlight>


{{omit from|AutoHotkey}}
{{omit from|AutoHotkey}}