Today's Common Lisp Project of the Day is "dynamic-mixins".

This is an interesting library which allows to add and remove mixin classes to the CLOS objects on the fly!
Common Lisp allows to change object's class, but this library goes further.

It keeps track which mixins were already added to the object and allows to add new or to remove existing!
To demonstrate, how this works, let's pretend we have a graphics system where each figure can be filled with color and/or can have rounded corners.

And we can have generic methods behave differently depending on traits of the figure:
Now we can construct the box object and simulate how it evolves over time when the user decides to make it's corner smoother and to fill it with a color:
The only problem I found is that it is impossible to pass initargs to the ensure-mix function. Because of that, slots which we added along with the mixin, remain unbound.

But I found the solution to this problem:
If you are found this thread interesting, then you also might like a post about dynamic-classes system:

https://40ants.com/lisp-project-of-the-day/2020/08/0171-dynamic-classes.html
You can follow @svetlyak40wt.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: