Mini-project: proto-slots

I've just released proto-slots, a mini-project I created as part of Ambienome. From the README:

proto-slots provides a macro for defining prototypal accessor methods so that CLOS instances will support protoypal inheritance. Prototypal inheritance means that an instance's slots can inherit values from another instance, known in these docs as the "base object" (but more commonly known elsewhere as the "prototype").

I wrote the first version of what eventually because the def-proto-slots macro to solve a problem I described in my previous post:

But, for each shape instance to have its own color (or other such data in the future), each shape instance must have its own job, because the color would be a uniform contained in that job. If I set the color in the base job, all instances of that kind of shape would have the same color. But if each instance has its own job, I lose the benefit of having the vertex data stored in one place.

I solved this by letting a job have a "parent", from which it inherits anything it's missing, such as a program or elements. For vertex attribs and uniforms, the inheritance works by merging the parent's list of attribs/uniforms with the child's list, with any of the child's attribs/uniforms taking precedence when it has the same name as one of the parent's.

I realized later that I was going to need prototypal inheritance for other parts of Ambienome, too. For example, I'm pretty sure the creature class will use this pretty heavily. So, I took my ad hoc macro, made it more flexible (it now supports different "inheritance strategies"), and polished it up. Along the way I decided to release it as a separate library, to maybe save someone else the trouble of implementing this same sort of thing.

proto-slots is available at GitHub, released under the X11/MIT license. If you find a bug, make an issue. To submit a patch, fork my repo and send a pull request.

Previous post: Colored Shapes Next post: Complicated Code and Creative Blocks