comp.lang.ada
 help / color / mirror / Atom feed
From: Jacob Sparre Andersen <sparre@nbi.dk>
Subject: Re: SPARK code samples
Date: Thu, 12 Aug 2010 11:46:04 +0200
Date: 2010-08-12T11:46:04+02:00	[thread overview]
Message-ID: <87bp98rwo3.fsf@hugsarin.sparre-andersen.dk> (raw)
In-Reply-To: op.vha0bzhexmjfy8@garhos

Yannick Duch�ne wrote:

> Ok. I choose a first one, the one named A+B:
> http://rosettacode.org/wiki/A%2BB#Ada

[...]

I think you have made the problem much too complicated.  Isn't this
sufficient?  (I haven't got a SPARK Examiner right here.)

------------------------------------------------------------
with SPARK_IO; --# inherit SPARK_IO;

--# main_program;
procedure A_Plus_B
   --# global in out SPARK_IO.Inputs, SPARK_IO.Outputs;
   --# derives SPARK_IO.Inputs  from SPARK_IO.Inputs &
   --#         SPARK_IO.Outputs from SPARK_IO.Inputs, SPARK_IO.Outputs;
is
   subtype Small_Integers is Integer range -1_000 .. +1_000;
   A, B       : Integer;
   A_OK, B_OK : Boolean;
begin
   SPARK_IO.Get_Integer (File  => SPARK_IO.Standard_Input,
                         Item  => A,
                         Width => 0,
                         Read  => A_OK);
   A_OK := A_OK and A in Small_Integers;
   SPARK_IO.Get_Integer (File  => SPARK_IO.Standard_Input,
                         Item  => B,
                         Width => 0,
                         Read  => B_OK);
   B_OK := B_OK and B in Small_Integers;
   if A_OK and B_OK then
      SPARK_IO.Put_Integer (File  => SPARK_IO.Standard_Output,
                            Item  => A + B,
                            Width => 4,
                            Base  => 10);
   else
      SPARK_IO.Put_Line (File => SPARK_IO.Standard_Output,
                         Item => "Input data does not match specification.",
                         Stop => 0);
   end if;
end A_Plus_B;
------------------------------------------------------------

Kind regards,

Jacob Sparre Andersen
--
Jacob Sparre Andersen Research & Innovation
Vesterbrogade 148K, 1. th.
1620 K�benhavn V
Danmark

Phone:    +45 21 49 08 04
E-mail:   jacob@jacob-sparre.dk
Web-site: http://www.jacob-sparre.dk/



  parent reply	other threads:[~2010-08-12  9:46 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-11  8:44 SPARK code samples Dmitry A. Kazakov
2010-08-11 11:38 ` Ada novice
2010-08-11 13:54   ` Yannick Duchêne (Hibou57)
2010-08-11 16:07   ` Mark Lorenzen
2010-08-11 16:33     ` (see below)
2010-08-11 16:45     ` Yannick Duchêne (Hibou57)
2010-08-11 16:50       ` Yannick Duchêne (Hibou57)
2010-08-11 17:10       ` Ada novice
2010-08-11 18:21         ` Yannick Duchêne (Hibou57)
2010-08-12 12:08           ` Ada novice
2010-08-12 22:03             ` Phil Thornley
2010-08-11 15:26 ` Yannick Duchêne (Hibou57)
2010-08-11 17:33   ` Dmitry A. Kazakov
2010-08-12  2:39     ` Yannick Duchêne (Hibou57)
2010-08-12  5:02       ` Jeffrey Carter
2010-08-12 13:31         ` Yannick Duchêne (Hibou57)
2010-08-12  7:16       ` cjpsimon
2010-08-12  7:29       ` Maciej Sobczak
2010-08-12 13:41         ` Yannick Duchêne (Hibou57)
2010-08-12  9:46       ` Jacob Sparre Andersen [this message]
2010-08-12 13:43         ` Yannick Duchêne (Hibou57)
2010-08-12 13:58           ` Jacob Sparre Andersen
2010-08-12  3:03     ` Yannick Duchêne (Hibou57)
  -- strict thread matches above, loose matches on Subject: below --
2010-08-11 17:32 Mark Lorenzen
2010-08-11 17:39 ` Ada novice
2010-08-11 17:45   ` (see below)
2010-08-11 18:00     ` Ada novice
2010-08-11 18:17       ` Yannick Duchêne (Hibou57)
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox