There is nothing as generic as that for structs. You can override how CLOS objects print and the output can be essentially anything you want. The issue comes with reading things back in. Depending on your needs, you could do something as simplistic as making the printed version of a "foo" object be:
- Code: Select all
(make-instance 'foo :slot1 'slot1-value :slot2 'slot2-value)
You would have to handle any inheritance yourself, whether single or multiple, and arrange to get all the slots there that you would need to recreate an object. Also, that is not the same as a reader macro, which is what structures use. Thus, using READ on the above output would give you back that whole code snippet, not a full CLOS object. You'd have to arrange to have that code executed to generate the object. You could create your own reader macro to essentially do what structures do (the #s syntax) and then call MAKE-INSTANCE under the hood.
Ultimately, CLOS is infinitely more flexible than structures, but there is a cost in complexity. If you know that structures will work for you and you can't foresee that you'll need CLOS right away, I'd go with structures. On the other hand, if you can easily envision that things are going to need to get more complex right away, then CLOS is probably a better solution as it will scale for the long term to incorporate more requirements easily.