comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: String declaration and initialization
Date: Fri, 23 May 2008 10:18:32 +0200
Date: 2008-05-23T10:18:25+02:00	[thread overview]
Message-ID: <gh6lebmmq9jr$.1dmos1a2qi24q$.dlg@40tude.net> (raw)
In-Reply-To: 4835A3B0.4010101@gmail.com

On Thu, 22 May 2008 16:47:44 +0000, S�bastien wrote:

>> declare
>>    function Test return String is -- Ada has scoped subprograms
>>    begin
>>       case Some_Test is
>>          when Test_1 => return "Test1";
>>          ...
>>       end case;
>>    end Test;
>>    Buffer: constant String := Test;
>> begin
>>    My_Treatment_1 (Buffer);
>>    ...
> 
> Good idea, but there are some other treatments in the case actually.
> 
> something like:
> buffer := test1;
> buffer_type := 3;
> and so on.
> 
> So if I use another function, I have to implement 2 cases in order to do it.

No. Make a record of the test name and the test type:

declare
   type Test_Type is range 1..20;
   type Test_Case (Length : Positive) is record
      Kind : Test_Type;
      Name : String (1..Length);
   end record;
   function Test return Test_Case is -- Ada has scoped subprograms
   begin
      case Some_Test is
         when Test_1 => return (Length => 5, Name => "Test1", Kind => 3);
         ...
      end case;
   end Test;
   Buffer: constant Test_Case := Test;
 begin
    My_Treatment_1 (Buffer.Name);

[ Observe, that the function Test is nothing but a classical factory. ]

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2008-05-23  8:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-22 15:47 String declaration and initialization Sébastien
2008-05-22 16:05 ` Dmitry A. Kazakov
2008-05-22 16:47   ` Sébastien
2008-05-23  8:18     ` Dmitry A. Kazakov [this message]
2008-05-23  9:33       ` Sébastien
2008-05-22 16:16 ` Matthew Heaney
2008-05-22 16:58   ` Sébastien
2008-05-22 17:11     ` Robert A Duff
2008-05-22 18:16     ` Matthew Heaney
2008-05-22 20:01     ` Jeffrey R. Carter
2008-05-22 16:40 ` Jean-Pierre Rosen
2008-05-22 18:09 ` Martin Krischik
replies disabled

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