Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: 5.10: Are scoped constants possible?

by TimToady (Parson)
on Dec 28, 2007 at 18:18 UTC ( [id://659369]=note: print w/replies, xml ) Need Help??


in reply to Re: 5.10: Are scoped constants possible?
in thread 5.10: Are scoped constants possible?

It doesn't look like it. Exegesis 4 does have a lexical constant declaration,

my $n is constant = 11;

but my copy of Perl 5.10 doesn't like it...

This should not be too terribly surprising, since the Exegesis is about Perl 6, not Perl 5. In any case, that is an ancient document, and these days that particular syntax is invalid even in Perl 6, because we've split the concept of constantness in two. As noted elsewhere in this thread, you can't do constant folding unless the compiler actually knows what the constant is going to be at compile time. So we distinguish such true constants from the "fake" constants that are known to stay constant only over a given dynamic scope. Syntactically they are also distinguished:
constant $n = 11;
vs
my $n is readonly = recalculate()
Note that function parameters in Perl 6 default to readonly, not constant, since the actual value can vary from call to call, and hence cannot be constant-folded.

In any case, if you want to quote Perl 6 documents, it's more useful to track the Synopses rather than the Exegeses, and do so at a more up-to-date site. (And, in fact, if you'd gotten your copy of Exegesis 4 from there, it would have had various annotations explaining where the Exegesis was out-of-date.)

Replies are listed 'Best First'.
Re^3: 5.10: Are scoped constants possible?
by quester (Vicar) on Dec 29, 2007 at 21:49 UTC
    Mea culpa. I guess I was focusing too much on 5.10 marking the word "is" as a syntax error.

    Thanks very much for the pointer to the Perl 6 documentation!

    ... by the way, does anyone know why Google hasn't been indexing http://www.perlcabal.org/? That's the pits!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://659369]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-19 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found