The following contributions are taken from the AdaCore Gem of the Week series. Gems are expert tips and insights that will help you get the most out of Ada 2005. The full collection of gems can be found at http://www.adacore.com/home/ada_answers, where you may obtain the source code and post comments as well. Gem #10: Limited Types in Ada 2005 Extended Return Statements Author: Bob Duff, AdaCore Abstract: Ada Gem #10 An extended_return_statement may be used to give a name to the result object being created by a function. Let s get started ¦ A common idiom in Ada 95 is to build up a function result in a local object, and then return that object: function Sum (A : Array_Of_Natural) return Natural is Result : Natural := 0; begin for Index in A Range loop Result := Result + A (Index); end loop; return Result; end Sum; Ada 2005 allows a notation called the extended_return_statement, which allows you to declare the result object and return it as part of one statement. It looks like this: function Sum (A : Array_Of_Natural) return Natural is begin return Result : Natural := 0 do for Index in A
/lp/association-for-computing-machinery/gem-10-limited-types-in-ada-2005-extended-return-statements-8GvT3TVurS