Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Shouldn't references be readonly? (updated)

by LanX (Cardinal)
on Aug 06, 2020 at 12:08 UTC ( #11120421=note: print w/replies, xml ) Need Help??


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

my main point is that things like this

 map { ++$_ } [1,2,3]

should throw an error, because the mutation of a reference itself doesn't make any sense.

And I was asking if there is a reason why they don't.

The whole discussion about "literals" is unfortunately only distracting,

(though Wikipedia is on my side: Literal (computer programming): "a notation for representing a fixed value in source code" but I don't wanna continue this.

NB: fixed doesn't mean (compile-time) constant. It means not variable)

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

Replies are listed 'Best First'.
Re^3: Shouldn't references be readonly? (updated)
by ikegami (Pope) on Aug 07, 2020 at 01:03 UTC

    The whole discussion about "literals" is unfortunately only distracting

    uh, I didn't bring up literals at all. It's an ambiguous word which may or may not include [4,5,6] depending on who you ask. It's useless to talk about literals.

    You asked why it wasn't like "TEST", 42 and undef, and I told you why.

    If you want to ask a different question now, fine.


    map { ++$_ } [1,2,3] should throw an error

    After all the fuss you made about inconsistency when you thought it wasn't consistent, you now want to make it inconsistent?

    No, assigning a number to a scalar that previously contained a reference is odd, but it shouldn't be an error.

      Ok, I'd like to contradict myself.

      I'd actually be ok with making "unassigned" scalars read-only. That includes [...], $x.$y, <>, etc.

      It might have performance implications, but they should be extremely tiny.

      It would break some code (such as my @lines = map { chomp; } <>;), but I think the benefits might be larger.

        > It would break some code

        I think if it comes to simple scalar types like strings this would result in a migration nightmare.

        Hence I wouldn't include the cases like $x.$y, <>, etc at least by default.

        Refs on the other hand should be immutable, because the result is always junk.

        But I doubt we have the resources to implement that anyway.

        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://11120421]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-12-02 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (41 votes). Check out past polls.

    Notices?