Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^5: Shouldn't references be readonly?

by dave_the_m (Monsignor)
on Aug 05, 2020 at 18:38 UTC ( #11120339=note: print w/replies, xml ) Need Help??


in reply to Re^4: Shouldn't references be readonly?
in thread Shouldn't LITERAL references be readonly? (updated)

Which of the following do you regard as a literal array:
[] [1,2,3] [1,2,$x]
I regard none of them as literal. [] {} are constructors; they are just syntactic sugar for a function which takes a list and returns a reference to an anonymous aggregate, e.g.
[1,2,3] # is the same as anon_array(1,2,3); sub anon_array { my @a = @_; \@a }

Dave.

Replies are listed 'Best First'.
Re^6: Shouldn't references be readonly? (updated)
by LanX (Cardinal) on Aug 05, 2020 at 18:51 UTC
      All I can say is that I personally strongly disagree with your use of term "literal" in this context, and I think that any attempt to draw an analogy between 1 and 1 is specious. The former is a literal value appearing in the source code and used as a compile-time constant. The latter is a run-time list constructor.

      But regardless of that, there is still the question of whether the reference returned by [] and {} should be marked readonly. I suppose it could be but Larry never thought to do so, and there doesn't seem any point in changing it now.

      Dave.

        > But regardless of that, there is still the question of whether the reference returned by [] and {} should be marked readonly. I suppose it could be but Larry never thought to do so,

        Thanks, at least someone beside Hauke who is not trying to convince me that the issue doesn't exist at all. \o/

        > and there doesn't seem any point in changing it now.

        Well ... catching errors would be an issue, don't you think?

        But like always with old errors, I wouldn't surprised if they became "features".

        After changing, some CPAN modules might break because they did something like

        sub func { $_[0] //= { the_default => "values" }; ... }

        which is a broken approach to default values ...

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        (you forgot to put [1] into code-tags)

        > The former is a literal value appearing in the source code and used as a compile-time constant.

        Well a compile-time constant with varying refs? Looks pretty much like just another constructor like [1] to me.

        use strict; use warnings; use Data::Dump qw/pp dd/; use constant a => 1; $\="\n"; print \1; # SCALAR(0xdf00e0) print \1; # SCALAR(0xdef540) print \(a); # SCALAR(0x2a19c70) print \(a); # SCALAR(0x2a19c70)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2020-10-31 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (286 votes). Check out past polls.

    Notices?