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


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!)