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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.165.197 with SMTP id o188mr6873374ioe.34.1438416391540; Sat, 01 Aug 2015 01:06:31 -0700 (PDT) X-Received: by 10.140.82.85 with SMTP id g79mr67301qgd.35.1438416391507; Sat, 01 Aug 2015 01:06:31 -0700 (PDT) Path: buffer1.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!f3no5777888igg.0!news-out.google.com!78ni1862qge.1!nntp.google.com!z61no4555727qge.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 1 Aug 2015 01:06:31 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=81.203.145.32; posting-account=AFCLjAoAAABJAOf_HjgEEEi3ty-lG5m2 NNTP-Posting-Host: 81.203.145.32 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> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <25e8deb9-a967-4856-97cb-4257e1ba7fa4@googlegroups.com> Subject: Re: Running a preprocessor from GPS? From: EGarrulo Injection-Date: Sat, 01 Aug 2015 08:06:31 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: number.nntp.giganews.com comp.lang.ada:194595 Date: 2015-08-01T01:06:31-07:00 List-Id: On Saturday, August 1, 2015 at 9:19:05 AM UTC+2, Simon Wright wrote: > EGarrulo writes: > > > On Friday, July 31, 2015 at 7:54:52 PM UTC+2, Jeffrey R. Carter wrote: > >> Many of the "design patterns" are actually implementation patterns to > >> work around deficiencies in the languages used in the book. An > >> obvious example is the "singleton pattern". In Ada, a singleton is > >> simply a pkg. It's only a problem that needs a pattern in languages > >> that lack modules. > > > > But a singleton would be instantiated when the "Get_Instance" function > > gets called by client code, not when a module gets loaded. Or does > > Ada load a package at the first call? > > According to Wikipedia, a singleton "is useful when exactly one object > is needed to coordinate actions across the system". And encapsulating > that object in a package meets that criterion. But all languages that I know let you do that, including C. Their concept of a package may be informal, but it is there. > Isn't a Get_Instance function a way of getting the desired effect in C++ > etc, rather than a necessary detail of the pattern? I can see that it > allows you to postpone creating the singleton instance until a time of > your choosing, rather than the Ada way of doing it during package > elaboration in a sequence chosen by the compilation/build engine. I can't see how Ada lets you postpone the creation of a singleton until a time of your choosing, without resorting to Get_Instance. What is the equivalent of this code: if Some_Condition then Singleton := Singleton_Package.Get_Instance; -- Use singleton. end if; without using Get_Instance? I have tried: 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?