In many languages, functions can be nested, resulting in outer functions and inner functions. The inner function can access variables from the outer function. In most languages, the inner function can also modify variables in the outer function.



Task
 
Write a program consisting of two nested functions that prints the following text.

1. first
2. second
3. third

The outer function (called MakeList or equivalent) is responsible for creating the list as a whole and is given the separator ". " as argument. It also defines a counter variable to keep track of the item number. This demonstrates how the inner function can influence the variables in the outer function.

The inner function (called MakeItem or equivalent) is responsible for creating a list item. It accesses the separator from the outer function and modifies the counter.



References

 Nested function


with Ada.Text_IO;
 
procedure Nested_Functions is -- 'Nested_Functions' is the name of 'main' 
 
   type List is array(Natural range <>) of String(1 .. 10);
 
   function Make_List(Separator: String) return List is
      Counter: Natural := 0;
 
      function Make_Item(Item_Name: String) return String is
      begin
	 Counter := Counter + 1; -- local in Make_List, global in Make_Item
	 return(Natural'Image(Counter) & Separator & Item_Name);
      end Make_Item;
 
   begin
      return (Make_Item("First "), Make_Item("Second"), Make_Item("Third "));
   end Make_List;
 
begin -- iterate through the result of Make_List
   for Item of Make_List(". ") loop
      Ada.Text_IO.Put_Line(Item);
   end loop;
end Nested_Functions;