lazyvec
lazyvec copied to clipboard
Use custom helper functions after deserializing a lazyvec
The user-defined methods for the lazyvec
are serialized along with the vector data. Upon deserialization, these methods will be available as list objects and called from the ALTREP API automatically. When these methods need helper functions, the user has to specify those separately, perhaps in a additional argument to lazyvec
(as a list).
For simplicity, the user can add required helper functions to the user metadata (as a list for example). These methods can also be used to attach additional packages if needed. We can add an init()
method to the list of user methods for loading and checking these dependencies.
It would be nice to be able to run the user-defined methods in the environment of a custom package. That way, a new package can be created that has a dependency on lazyvec
. A custom lazyvec can be created and serialized to disk.
Upon deserialization, the new package will automatically be loaded (this is supported by the ALTREP framework). Any helper functions can be defined in the user package with such a setup, without the need to store them inside the ALTREP vector.
Because the vector will be registered with class lazyvec
, only the lazyvec
package will be automatically loaded upon deserialization. So methods from lazyvec
or it's parent environments can be used in the custom user methods. We can provided a container for an init()
user method that can be used to set the environment for executing the user methods to a new package environment. When that package has a dependency on lazyvec
, also lazyvec
methods will be available on the search path.
If the custom lazyvec
vector is not created from a user package, any helper functions could be placed in a new environment. Alternatively, the user could add those methods to the metadata argument (if it's a list).