Multiple Return Values in Ada
Ada supports multiple return values through the use of out parameters. This feature is commonly used to return both result and error values from a procedure.
To run the program, save it as multiple_return_values.adb
and use the Ada compiler:
In Ada, we use procedures with out parameters to simulate multiple return values. The Vals
procedure takes two out
parameters, which are filled with the values we want to return.
In the begin
block, we call Vals
and immediately use the returned values. Ada doesn’t have a built-in print function like fmt.Println
, so we use Ada.Text_IO.Put_Line
to output the values. We also need to convert the integers to strings using Integer'Image
.
If you only want a subset of the returned values, you can simply ignore the ones you don’t need. Ada doesn’t have a blank identifier like Go’s _
, but you can achieve the same effect by just not using one of the out parameters.
Ada’s approach to multiple return values via out parameters offers similar functionality to Go’s multiple return values, allowing for clear and efficient handling of multiple results from a single subprogram call.