You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm implementing a toy lisp based on kanaka/mal using bifurcan, and I've come across two cases where it would be useful to be able to create subclasses of the bifurcan structures. These are difficult to create since the methods create new instances of the structures and there's no way to create a subclass when that happens.
MAL requires me to support Clojure-style lists and vectors. I'd like to use bifurcan's List for both since it supports the efficient operations of both, but I need to be able to record which was read (i.e. list or vector) so that I can later print it correctly. There's no really good way to do this at the moment. I ended up creating a Vector class implementing IList which delegates to an internal List, and for the methods which return a new List I then wrap them in a new Vector, but that's pretty ugly.
I'd like to implement something like Clojure's IObj protocol to allow metadata to be stored on the collections too, but that's equally tricky. I could probably implement some equally ugly workaround, but a nicer way to do this would be great.
I've only looked at List so far, but it seems like the operations create new instances via the private List(boolean linear, Node root, int prefixLen, Object[] prefix, int suffixLen, Object[] suffix) constructor. Could the new instances instead be created by calling a protected method which in List just calls that constructor, but in a subclass could create a Vector, IObjList or whatever?
I'm not sure what the implications are for other interfaces such as Concat though.
The text was updated successfully, but these errors were encountered:
I'm sorry it took me so long to notice this issue. The wrapping approach is what I intend to do whenever I get around to an official Clojure shim over this library, but I have no issue with making that constructor protected, if that would suffice for your issue.
I'm implementing a toy lisp based on kanaka/mal using bifurcan, and I've come across two cases where it would be useful to be able to create subclasses of the bifurcan structures. These are difficult to create since the methods create new instances of the structures and there's no way to create a subclass when that happens.
I've only looked at List so far, but it seems like the operations create new instances via the private
List(boolean linear, Node root, int prefixLen, Object[] prefix, int suffixLen, Object[] suffix)
constructor. Could the new instances instead be created by calling a protected method which in List just calls that constructor, but in a subclass could create a Vector, IObjList or whatever?I'm not sure what the implications are for other interfaces such as Concat though.
The text was updated successfully, but these errors were encountered: