develooper Front page | perl.perl5.porters | Postings from May 2000

Re: Proposed pragma: readonly - summary

From:
Mark Summerfield
Date:
May 22, 2000 12:22
Subject:
Re: Proposed pragma: readonly - summary
Message ID:
39297E06.CDC9710E@queenwood.screaming.net
Tom,

Tom Christiansen wrote:
[snip]
> >       const $READONLY = 99 ; # OR use readonly '$READONLY' => 99 ;
> >       *MYREADONLY = \'splat!' ;
> >       print $READONLY ; # Yep, prints "splat!" and no warnings
> 
> >Looks like you can't have genuinely readonly scalars in perl unless you
> >use ties...
> 
> Why should this be an issue?  Just because you can't diddle $foo doesn't
> mean you can't diddle the *foo typeglob.
[snip]

Its not that I don't want to be able to mess with *foo - that's useful;
it is just that I really want to have constants that will stay that way
and still can't find a good way of doing it.

> Coming soon from a Larry near you:
> 
>     At some point, we'll enable the use of a C<constant> attribute
>     on variable declarations:
> 
>         my $PI : constant = 4 * atan2(1,1);
> 
>     This has all the advantages of being a variable rather than a
>     subroutine.  It has all the disadvantages of not being implemented yet.
> 
> --tom

That's good news to me. Over the years all my perl 'annoyances' have
evaporated as I learnt more, except for not being able to have decent
constants. (Although new ones have come along of course:)

The first thing I'd like to be able to do is export my constants...
which I can't do with my's. I feel that constants do need to be
exportable to be fully useful. (See my reply to Ian Phillipps,
following, for a note on that.)

_______________________________________________
Mark Summerfield       http://www.perlpress.com






nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About