On Wed, Aug 17, 2005 at 09:37:08PM +0000, Luke Palmer wrote:
: On 8/17/05, Larry Wall <[EMAIL PROTECTED]> wrote:
: > You could still reason about it if you can determine what the initial
: > value is going to be.  But certainly that's not a guarantee, which
: > is one of the reasons we're now calling this write/bind-once behavior
: > "readonly" and moving true constants to a separate declarator:
: > 
: >     my $pi is readonly;
: >     $pi = 3;
: > 
: > vs
: > 
: >     constant $pi = 3;
: > 
: > or
: > 
: >     constant Num pi = 3;
: > 
: > or if you like, even
: > 
: >     constant π = 3;
: 
: Minor detail: when does the right side get evaluated?  That is, what
: happens here:
: 
:     constant pi = make_pi();
:     sub make_pi() { 4*atan2(1,1) }

That should fail, I think.  Constant pseudo assignment is equivalent to
"is begin(make_pi())", in the same way that other pseudo-assignments
pay attention to the declarator to figure out when they really run.
And I think we want constants lexically scoped and known to the
compiler so it can do immediate constant folding.  This also has the
nice property that it visually distinguishes values intended for
consumption by the compiler from values intended for consumption for
the runtime.

: If you want this to succeed, then this must fail:
: 
:     constant pi = 4*atan2(1,1);
:     BEGIN { say "pi = {pi}" }

That one succeeds.

: Is it even possible to evaluate constants at CHECK time and then
: constant-fold them in before the program is run?

I think that sort of chicanery is best left for

    sub pi() {...}
    say "pi = {pi}";
    sub pi() { 4*atan2(1,1) };

Larry

Reply via email to