Open jeapostrophe opened 3 years ago
Edit: just realized this is the racklog repo.
I agree, it would be nice to have a generic way for specifying how to determine things like equality, hashing, and in this case unification. However, instead of having something like (get-components obj)
which returns a vector for comparisons, hashing, etc., Rhombus should use a visitor object (visit-components obj visitor)
. You would call the visitor as (visit child1) (visit child2)
. The visitor is the one that calls visit-components
so it can keep track of the full tree structure if it cares about that.
A related use case is how to handle deserialization? The conventional way to do this is to use an approach like the above for serialization, but then you need a way to reconstruct object in the same order. You could potentially do it by extending the above model to instead call visit by doing (visit child1-lens) (visit child2-lens)
and presumably having some default version of the struct/object that one can modify. The only thing I don't like with the lens approach is that this is inefficient if the struct allows mutation. Maybe you could have the lens instead by a vector of functions with a size of 1-3 elements. The first element is always a getter, the second function is an immutable setter, and the third element is a mutable setter.
I am aware that the conventional way in Racket to do serialization are via the read
and write
functions, I just think serialization is another space where having a generic way to traverse structures is useful.
Right now, Racklog's unify "sees through" transparent structs and unifies their contents, but all other structs are treated atomically. (See #16) It would be good to make some sort of property that exposes a struct (or portion of) as a list for the purposes of walking. It is plausible that this could be generalized further for things like comparers, like in https://github.com/racket/rhombus-brainstorming/issues/149