From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2f343e3986ead102 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!feeder.news-service.com!club-internet.fr!feedme-small.clubint.net!feeder1-1.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: String declaration and initialization Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1sx14jlsjttyu$.me8s3y39ipru.dlg@40tude.net> <4835A3B0.4010101@gmail.com> Date: Fri, 23 May 2008 10:18:32 +0200 Message-ID: NNTP-Posting-Date: 23 May 2008 10:18:25 CEST NNTP-Posting-Host: eb39086e.newsspool3.arcor-online.net X-Trace: DXC=fGcW4j98>X@2:OR3:3gaE@McF=Q^Z^V3H4Fo<]lROoRA8kFO79Lo>J[UI?@ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:299 Date: 2008-05-23T10:18:25+02:00 List-Id: 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