fork download
  1. With Ada.Text_IO; Use Ada.Text_IO;
  2.  
  3. procedure Test is
  4.  
  5. package Example is
  6.  
  7. type My_Type is limited private;
  8.  
  9. procedure Initialize(Self : in out My_Type; Value : Integer);
  10. procedure Print(Self : My_Type);
  11.  
  12. private
  13.  
  14. type My_Type is limited record
  15. Value : Integer := 0;
  16. end record;
  17.  
  18. end Example;
  19.  
  20. package body Example is
  21. procedure Initialize(Self : in out My_Type; Value : Integer) is
  22. begin
  23. Self.Value := Value;
  24. end Initialize;
  25.  
  26. procedure Print(Self : My_Type) is
  27. begin
  28. Ada.Text_IO.Put_Line(Self.Value'Image);
  29. end Print;
  30. end Example;
  31.  
  32. -- HERE: Turn the procedure into a funciton with
  33. -- extended return syntax.
  34. function Make (Value : Integer) return Example.My_Type is
  35. begin
  36. return Result : Example.My_Type do
  37. Example.Initialize(Result,Value);
  38. end return;
  39. end Make;
  40.  
  41. Thing : Example.My_Type := Make(21);
  42.  
  43. begin
  44. Example.Print(Thing);
  45. end Test;
Success #stdin #stdout 0s 4296KB
stdin
Standard input is empty
stdout
 21