Skip Menu |
Report information
Id: 125975
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: dakkar <dakkar [at] thenautilus.net>
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



From: Gianni Ceccarelli <dakkar [...] thenautilus.net>
Date: Thu, 3 Sep 2015 13:57:29 +0100
To: rakudobug [...] perl.org
Subject: [BUG] INIT-time constants are awkward
Download (untitled) / with headers
text/plain 542b
Consider this snippet: constant NOW = DateTime.now; That is a BEGIN-time declaration + initialisation. C<NOW> will contain the time of compilation. On the other hand: my \NOW = DateTime.now; does run-time initialisation, so you get a different time at each run. There does not seem to be a nice way of having a C<constant> with an INIT-time initialiser: constant NOW = INIT DateTime.now; sets C<NOW> to C<Mu>, since a BEGIN time that INIT block has not run. Is there already a working way to do that? Should there be? Thanks.
Subject: [NYI] our \NOW = DateTime.now;
Download (untitled) / with headers
text/plain 863b
On Thu Sep 03 05:57:58 2015, dakkar wrote: Show quoted text
> Consider this snippet: > > constant NOW = DateTime.now; > > That is a BEGIN-time declaration + initialisation. C<NOW> will contain > the time of compilation. > > On the other hand: > > my \NOW = DateTime.now; > > does run-time initialisation, so you get a different time at each run. > > There does not seem to be a nice way of having a C<constant> with an > INIT-time initialiser: > > constant NOW = INIT DateTime.now; > > sets C<NOW> to C<Mu>, since a BEGIN time that INIT block has not run. >
Correct, and there's no sensible way to make that work. Show quoted text
> Is there already a working way to do that? Should there be? >
Yes, an "our" scoped variable should have its initializer run at our time: our \NOW = DateTime.now; That's not implemented yet, so re-purposing this ticket for implementing that. :-)
Still NYI (2017.11, HEAD(5929887))

On 2015-09-04 08:25:24, jnthn@jnthn.net wrote:
Show quoted text
> On Thu Sep 03 05:57:58 2015, dakkar wrote:
> > Consider this snippet:
> >
> > constant NOW = DateTime.now;
> >
> > That is a BEGIN-time declaration + initialisation. C<NOW> will
> > contain
> > the time of compilation.
> >
> > On the other hand:
> >
> > my \NOW = DateTime.now;
> >
> > does run-time initialisation, so you get a different time at each
> > run.
> >
> > There does not seem to be a nice way of having a C<constant> with an
> > INIT-time initialiser:
> >
> > constant NOW = INIT DateTime.now;
> >
> > sets C<NOW> to C<Mu>, since a BEGIN time that INIT block has not run.
> >
> Correct, and there's no sensible way to make that work.
>
> > Is there already a working way to do that? Should there be?
> >
> Yes, an "our" scoped variable should have its initializer run at our
> time:
>
> our \NOW = DateTime.now;
>
> That's not implemented yet, so re-purposing this ticket for
> implementing that. :-)




This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org