http://www.perlmonks.org?node_id=11120337


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

> Perl doesn't have literal arrays ... a reference to an anonymous array,

Perlglossary

literal

A token in a programming language, such as a number or string, that gives you an actual value instead of merely representing possible values as a variable does.

anonymous

Used to describe a referent that is not directly accessible through a named variable. Such a referent must be indirectly accessible through at least one hard reference. When the last hard reference goes away, the anonymous referent is destroyed without pity

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

  • Comment on Re^4: Shouldn't references be readonly?

Replies are listed 'Best First'.
Re^5: Shouldn't references be readonly?
by dave_the_m (Monsignor) on Aug 05, 2020 at 18:38 UTC
    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.

        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.