Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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

by LanX (Sage)
on Aug 07, 2020 at 10:34 UTC ( #11120460=note: print w/replies, xml ) Need Help??

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

> 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

Replies are listed 'Best First'.
Re^6: Shouldn't references be readonly? (updated)
by ikegami (Patriarch) on Aug 07, 2020 at 19:54 UTC
    @a = map { $_ = 3; } [];

    is no more or less junk than

    @a = map { $_ = 3; } $x.$y;

    Are you therefore talking about [] + 1? Making the reference read-only is not going to catch that.

      There are far more situations where it might make sense to append or add something to a simple type.

      Not so with refs, no way a .= or a += will lead to anything meaningful.

      Well except when blessed and overloaded. But that's far fetched.

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

        Making the var read-only won't prevent concatenation or addition, so it doesn't matter that $x . [] or $x + [] doesn't make sense.[1]. This isn't relevant to the topic at hand.

        The only thing making it read-only will do is prevent assignment, and map { $_ = 3 } $x.$y makes no more sense than map { $_ = 3 } [].

        Either prevent both of them, or prevent neither of them. No need for baseless inconsistencies.

        1. That said, $ref+0 makes some sense for refs to things other than objects with overloads, and both concatenation and addition make sense for refs to objects with overloads (which aren't farfetched at all!)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2023-01-30 14:29 GMT
Find Nodes?
    Voting Booth?

    No recent polls found