From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=BAYES_00,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: deferred constants Date: Wed, 7 Jul 2021 22:40:25 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <5db8eeb4-f3fc-49a7-b588-6a4b25bdbafcn@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 7 Jul 2021 20:40:26 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="6e3fbf440c30967a9a7e3c20fd18f2a9"; logging-data="13521"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OCfWpqN6rVhLOVWW2KSc7xPZ97JLlj1U=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 Cancel-Lock: sha1:eyrqafxum0CydcN0BJpszhM+1WA= In-Reply-To: <5db8eeb4-f3fc-49a7-b588-6a4b25bdbafcn@googlegroups.com> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:62343 List-Id: On 7/7/21 9:31 PM, Matt Borchers wrote: > Is it possible to define a constant in a package body that has it's initialization deferred to elaboration? > > with Gnat.RegExp; > package body > pat : constant Gnat.RegExp.RegExp; > begin > pat := Gnat.RegExp.compile( "..." ); > end; Deferred constants are defined in ARM 7.4 (http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-7-4.html), which says they may only appear in the visible part of a pkg spec, and the full declaration must appear in the private part of the same pkg. So what you're trying is illegal. In cases like this, you declare the object as a variable, with comments indicating that it is set later and is then constant. of course, in the example, one can simply do Pat : constant Gnat.RegExp.RegExp := Gnat.RegExp.Compile ( "..." ); but there are cases where this is not possible. -- Jeff Carter "He had no conception of the instrument. He was blowing into it." Take the Money and Run 135