Call a function: Difference between revisions

m
→‎{{header|Ada}}: Linguistic fixes
m (→‎{{header|Ada}}: Linguistic fixes)
Line 24:
=={{header|Ada}}==
 
* Ada provides two kinds of subroutines: procedures, without return values, and functions, with return values. The return values of proceduresfunctions must be used by the callers. If you don't want doto deal with the return value, call a procedure instead.
 
* As a rule of thumb, an Ada compiler is free to pass arguments either by value or by reference. Parameters have a mode, however: either 'in' or 'out' or 'in out'. It is prohibited to write somthinganything to an 'in' parameter. The next language Standard, Ada 2012, will support functions with 'out' and 'in out' mode parameters, so far, only procedures could have parameters with non-'in' modes. So any of the following statements for Ada functions holds for Ada procedures as well.
 
* There are no differences between between calling built-in vs. user defined functions.
 
* Functions without parameters can be called by omitting the parameter list (no empty brackets!):<lang Ada>S: String := Ada.Text_IO.Get_Line;</lang>
Line 38:
C : Integer := F(12, 1); -- something different</lang>
 
* If the number of parameters of F wherewere fixed to two (by omitting the ":= 0" in the specification), then B and C would be OK, but A wouldn't.
 
* Ada does not support functions with a variable number of arguments. But a function argument can be an unconstrained array with as many values as you want:<lang Ada>type Integer_Array is array (Positive range <>) of Integer;
Line 63:
-- taking two Integers and returning an Integer.</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>Positional := H(A, F'Access);
Named := H(Int => A, Fun => F'Access);
Mixed := H(A, Fun=>F'Access); </lang>
Anonymous user