Closed rikivillalba closed 2 months ago
There's not technically a need for that:
library(S7)
someclass <- new_class("someclass", properties = list(
action = new_property(
getter = function(self) self@action,
setter = function(self, value) {
self@action <- toupper(value)
self
}
)
))
x <- someclass()
x@action <- "some action"
x@action
#> [1] "SOME ACTION"
x
#> <someclass>
#> @ action: chr "SOME ACTION"
Created on 2024-05-26 with reprex v2.1.0
Sorry i was not aware of it, but my conclusion came because evaluating the property without prior assignment exhausted the stack (so I thought that self@action simply recursed the getter, that is not the case as your example shows).
However i get the error when the prop is not initialized.
In my case this happens:
library(S7)
someclass <- new_class("someclass", properties = list(
action = new_property(
getter = function(self) self@action,
setter = function(self, value) {
self@action <- toupper(value)
self
},
default = "some action"
)
))
x <- someclass()
x@action
#> Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Created on 2024-05-26 with reprex v2.1.0
I'll close this thread and open a new one with the appropiate name
Is there a possibility to hide by default properties starting with a dot at least in the default
print
andstr
methods? There could be the case when you use a "dynamic" property with getter and setter, and the true value is stored in an internal property you want to hide. i.e.:So I find this better:
Such a behaviour will provide a python-like soft encapsulation with dot names. Also will equate the behaviour of
base::ls()
(and that of the unif file system)