http://qs321.pair.com?node_id=11120366


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

(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

Replies are listed 'Best First'.
Re^9: Shouldn't references be readonly? (updated)
by dave_the_m (Monsignor) on Aug 06, 2020 at 08:51 UTC
    print \1; # SCALAR(0xdf00e0) print \1; # SCALAR(0xdef540)

    I don't understand what of interest that's supposed to show. The first line has a compile-time literal value 1, and a run-time operator, \. The second line has another literal and op. Whether the two literals resolve to the same SV internally is entirely down to how the compiler optimises things. As it happens perl doesn't look for common shared constants.

    (Also as it happens, \1 is constant-folded at compile time, in the same way that 1+2 is.)

      > I don't understand what of interest that's supposed to show.

      The fact that [...] resolves each time to a new AV was used as argument against being literal.

      Obviously most "literals" are not treated the way constants are. (with the exception of undef)

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

Re^9: Shouldn't references be readonly? (updated)
by chromatic (Archbishop) on Aug 06, 2020 at 00:41 UTC

    That... is actually a pretty good example.

    Run it through Deparse though, and:

    use strict; use warnings; use Data::Dump ('pp', 'dd'); use constant ('a', 1); $\ = "\n"; print \1; print \1; print \1; print \1;
      > Run it through Deparse though,

      And what do you think that proves?

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

        The same thing that you do: there's a subtlety of implementation that Deparse doesn't catch.