[Shootout-list] Cleaner Ada version of the sum-file bench

Pascal Obry pascal@obry.net
Thu, 17 Mar 2005 21:58:52 +0100


This should be faster than the previous version.

-- $Id: sumcol-gnat.code,v 1.5 2004/11/22 07:09:05 bfulgham Exp $
-- http://shootout.alioth.debian.org
-- by James S. Rogers
-- Simplified by Pascal Obry on 2005/03/17

with Ada.Text_IO;         use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure SumCol is
  Line : String (1 .. 128);
  Sum  : Integer := 0;
  Len  : Natural;
begin
  while not End_Of_File loop
    Get_Line (Item => Line, Last => Len);
    Sum := Sum + Integer'Value (Line (1 .. Len));
   end loop;
   Ada.Integer_Text_IO.Put (Item => Sum, Width => 0);
   New_Line;
end SumCol;

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595