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=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:a0c:cd10:: with SMTP id b16mr25233411qvm.21.1625690672682; Wed, 07 Jul 2021 13:44:32 -0700 (PDT) X-Received: by 2002:a25:8081:: with SMTP id n1mr36238108ybk.253.1625690672523; Wed, 07 Jul 2021 13:44:32 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 7 Jul 2021 13:44:32 -0700 (PDT) In-Reply-To: <5db8eeb4-f3fc-49a7-b588-6a4b25bdbafcn@googlegroups.com> Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.2.231 References: <5db8eeb4-f3fc-49a7-b588-6a4b25bdbafcn@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2e09faca-1f9a-43d3-99cb-6ae0e27a741cn@googlegroups.com> Subject: Re: deferred constants From: Shark8 Injection-Date: Wed, 07 Jul 2021 20:44:32 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:62345 List-Id: On Wednesday, July 7, 2021 at 1:31:34 PM UTC-6, Matt Borchers wrote: > Is it possible to define a constant in a package body that has it's initialization deferred to elaboration? > > For example... > > with Gnat.RegExp; > package body > pat : constant Gnat.RegExp.RegExp; > begin > pat := Gnat.RegExp.compile( "..." ); > end; > > Obviously it is not strictly necessary to create 'pat' as a constant, but it is ideal to define symbols as precise as possible. Without it being a constant, the compiler will obviously not check to make sure someone has not inadvertently overwritten it. > > GNAT gives me the following errors: > - constant declaration requires initialization expression > - deferred constant is frozen before completion > > The first error message is not true, but comes from the fact that the second IS true. Is there a way to postpone the freezing of a symbol until after elaboration? Use RENAMES? pat : Gnat.RegExp.RegExp renames Gnat.RegExp.compile( "..." ); Other than this, I would advise not using RegEx.