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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Running a preprocessor from GPS? Date: Sat, 01 Aug 2015 14:44:56 +0300 Organization: Tidorum Ltd Message-ID: References: <2df4698f-4c8e-457c-822d-209cb2f8ab5e@googlegroups.com> <014427b1-ff7a-4a69-82e6-0330af77ed96@googlegroups.com> <91f88d79-197c-419f-84a8-908e05967a2c@googlegroups.com> <135c2b00-d13c-4f5d-a586-8aca442d363b@googlegroups.com> <87380683vc.fsf@adaheads.sparre-andersen.dk> <347c6be9-c918-4bc0-9494-c93cd6740def@googlegroups.com> <4cb32c40-f659-490d-bbb6-73585fc069e8@googlegroups.com> <7e653a88-e690-431a-9df9-3fc691466e08@googlegroups.com> <25e8deb9-a967-4856-97cb-4257e1ba7fa4@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net NXcuhgJaseQaHZ2Rh9omIAzrhfygpeoMXGntLkIO4Vy7Q3EZbI Cancel-Lock: sha1:Kl3XopBIy1ZazgXwmsOsZAoNh6U= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:27295 Date: 2015-08-01T14:44:56+03:00 List-Id: On 15-08-01 13:47 , EGarrulo wrote: > On Saturday, August 1, 2015 at 10:32:47 AM UTC+2, Simon Wright wrote: >> EGarrulo writes: >> >>> if Some_Condition then >>> declare >>> with Ada; use Ada; >>> begin >>> Singleton := Singleton_Package.Singleton_Instance; -- Read variable. >>> -- Use singleton. >>> end; >>> end if; >>> >>> But the compiler complains that "aspect specifications not allowed >>> here". Or does "with Package" put a package in scope without >>> elaborating it until "use Package", and therefore I should have left >>> only the "use" directive? >> >> "with Pkg" can only occur in a compilation unit's context clauses. >> >> "use Pkg" can appear there, and also in a declarative region (e.g. your >> "declare" section). >> >> "use" has no effect on elaboration, only on visibility. See ARM 10.2, >> Program Execution. >> >> http://www.adaic.org/resources/add_content/standards/12rm/html/RM-10-2.html > > Thanks. Therefore there is no way to postpone the creation of a singleton > until client code needs it, by relying on package elaboration alone, right? > Therefore Ada -- too -- needs the Singleton pattern. Discussion of design patterns easily degenerates into a debate about terminology. To second Simon's post, an Ada (library-level) package, as a collection of state and operations, with necessarily exactly once instance of the state, matches the concept of a singleton object in all respects except as regards the "lazy initialization" thing, which to me is a very secondary aspect of singletons. If an Ada "singleton" package is a significant consumer of memory and/or initialization time, it is easy to arrange for most of the memory allocation and initialization to occur lazily, when the package (or that part of the package) is used for the first time. One way to do that is to insert a check for initialization at the start of every operation; another way is to have some kind of Get_Instance operation that initializes the package (i.e. "creates the singleton") and returns a handle that is a required parameter for all other operations. While elaboration order is defined by the "need" relationship between modules, this is the static relationship defined by the "with" clauses, and is satisfied before the main subprogram starts. Whether this means that Ada "needs" the singleton pattern is a moot point. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .