Skip to content
Prev 32912 / 63421 Next

reference counting bug related to break and next in loops

William Dunlap wrote:
it's interesting (if not "obvious") that

    i = 1;  y = 1:3
    (while (TRUE) {
       y[i] = 0
       if (i==2) break
       i = i +1
       y + 0 })
    # 0 2 3

does not reflect in the final value the modification made to y in the
second, incomplete iteration, and that

    i = 1;  y = 1:3
    (while (TRUE) {
       y[i] = 0
       if (i==2) break
       i = i +1
       y })
    # 0 0 3

does reflect this modification, yet

    i = 1;  y = 1:3
    (while (TRUE) {
       y[i] = 0
       if (i==2) { y = 1:3; break }
       i = i +1
       y })
    # 0 0 3

makes a copy of y on y = 1:3 and returns the previous value.  again,
this surely has a "straightforward" explanation in the copy-when-scared
mechanics, yet, intuitively, the returned value seems completely out of
place.
i'm truly impressed by s+'s superiority over r.
... with the current lousy documentation improved to match the actual
semantics.

vQ