Call a function: Difference between revisions

m
Line 19:
* Ada provides two kinds of subroutines: procedures, without return values, and functions, with return values. The return values of procedures must be used by the callers. If you don't want do 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 somthing 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.* ThereSo areany noof differencesthe betweenfollowing betweenstatements callingfor built-in vs. user definedAda functions (orholds procedures).for Then, the only distinction between functions andAda procedures inas Ada is the existence of a return valuewell.
 
* 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>
 
* Ada supports functions with optional parameters:<lang Ada>function F(X: Integer; Y: Integer := 0) return Integer; -- Y is optional
...
A : Integer := F(12);
Line 29 ⟶ 31:
C : Integer := F(12, 1); -- something different</lang>
 
* If the number of parameters of F where 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;
Anonymous user