Closed yutannihilation closed 6 months ago
Current behavior is super wierd for mutable semantics. This is because AltInteger
trait materializes on the first duplication and return it afterwards. But, elt()
looks at the original.
x <- savvyExamples:::altint()
x
#> [1] 1 2 3
# ...??
savvyExamples:::double_altint(x)
x
#> [1] 1 2 3
# ...???
x2 <- savvyExamples:::altint()
savvyExamples:::double_altint(x2)
x2
#> [1] 2 4 6
savvyExamples:::double_altint(x2)
x2
#> [1] 2 4 6
x2[1]
#> [1] 4
Created on 2024-04-30 with reprex v2.1.0
Okay. Even if I implement Dataptr
or Set_elt
, copy-on-modify rules. I'm giving up.
x <- savvyExamples:::altint_mutable()
x
#> [1] 1 2 3
.Internal(inspect(x))
#> @0x000001e99ff2ae30 13 INTSXP g0c0 [REF(5)] (MyAltIntMutable)
x[1L] <- 2L
.Internal(inspect(x))
#> @0x000001e9a210e968 13 INTSXP g0c2 [REF(1)] (len=3, tl=0) 2,2,3
Created on 2024-05-02 with reprex v2.1.0
Close https://github.com/yutannihilation/savvy/issues/224 (as a side effect)