Functions in Ada

Based on the provided input, here’s the translation of the Go code to Ada, formatted in Markdown suitable for Hugo:

Functions are central in Ada. We’ll learn about functions with a few different examples.

with Ada.Text_IO; use Ada.Text_IO;

procedure Functions is
   -- Here's a function that takes two Integers and returns
   -- their sum as an Integer.
   function Plus (A : Integer; B : Integer) return Integer is
   begin
      -- Ada doesn't require explicit returns, but it's good practice
      -- to include them for clarity.
      return A + B;
   end Plus;

   -- In Ada, you need to declare the types for each parameter separately,
   -- even if they are of the same type.
   function Plus_Plus (A : Integer; B : Integer; C : Integer) return Integer is
   begin
      return A + B + C;
   end Plus_Plus;

   Res : Integer;
begin
   -- Call a function just as you'd expect, with
   -- name(args).
   Res := Plus(1, 2);
   Put_Line("1+2 =" & Integer'Image(Res));

   Res := Plus_Plus(1, 2, 3);
   Put_Line("1+2+3 =" & Integer'Image(Res));
end Functions;

To run the program:

$ gnatmake functions.adb
$ ./functions
1+2 = 3
1+2+3 = 6

There are several other features to Ada functions. One is out parameters, which we’ll look at next.