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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Running a preprocessor from GPS? Date: Sat, 1 Aug 2015 09:48:16 +0200 Organization: cbb software GmbH Message-ID: <1skv40112ytpq.1natkyhrl6jk7$.dlg@40tude.net> 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> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: ChlmA4XFxcJoDoqGdDSflw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:27287 Date: 2015-08-01T09:48:16+02:00 List-Id: On Fri, 31 Jul 2015 11:20:35 -0700 (PDT), EGarrulo wrote: > 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? Well, since other responses regarding singletons were IMO wrong. Here is an answer from the OO POV. In Ada singleton is achieved directly by the language means. [ When Ada was designed there was no pattern stuff, which Jeffrey correctly characterized as workarounds. Yet Ada designers understood the problem, maybe unconsciously, and resolved it at the language level. ] Ada's singleton is an object of anonymous type. Many types allow object declarations of anonymous types, which guarantees single instance, because the type has no name. Array singleton: Singleton : array (1..3) of Integer; Task singleton: task Singleton is ... end task; Protected object singleton: protected Singleton is ... end task; Access type singleton (note access, not the target): Singleton : [not null] access ...; For other types the singleton pattern is a declaration of the type and the instance in the package body. This is probably what Jeffrey meant talking about packages: package body P is type Nobody_See_Me is ...; Singleton : Nobody_See_Me; P.S. Get_Instance is C++ gibberish because it cannot create/return unconstrained instances. In Ada you declare an object, singleton or not, and that creates it. End of story. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de