Call a function: Difference between revisions

m
Line 25:
* Ada provides for functions with optional parameters:<lang Ada>function F(X: Integer; Y: Integer := 0) return Integer;
...
A : Integer := F(12); -- F(12) is the same as F(12, 0)</lang>
B : Integer := F(12, 0); -- the same as A
C : Integer := F(12, 1); -- something different</lang>
 
* The caller is free to use either a positional parameters or named parameters, or a mixture of both (with positional parameters first) <lang Ada>XPositional := H(A, F'Access); -- positional
XNamed := H(Int => A, Fun => F'Access); -- named
XMixed := H(A, Fun=>F'Access); -- mixture </lang>
 
* Ada does not allow a variable number of arguments. But a function argument can be an unconstrained array with as many arguments as you want:<lang Ada>type Integer_Array is array (Positive range <>) of Integer;
Line 51 ⟶ 53:
 
X := H(A, F'Access) -- assuming X and A are Integers, and F is a function
-- taking two Integers and returning an Integer.</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
Anonymous user