[Openmcl-devel] [off-topic] Adding a slot to a class using the MOP
Ron Garret
ron at flownet.com
Mon Apr 22 15:26:25 PDT 2013
I'm writing a persistent object store, where the user can choose to provide their own primary key or use a system-generated UID. If they use the system-generated UID then it has to be stored somewhere, and a slot in the object being stored seems like the obvious place. But I'm open to suggestions. I actually have a workaround, which is to just require the user to provide a slot to store the key even if it's system generated, but that seems inelegant. It seems to me that this sort of thing ought not to be as hard as it apparently is.
Why would adding a slot programmatically cause any more problems that redefining a class with a different repertoire of slots? Isn't the whole point of the MOP to be able to do (among other things) exactly that? Isn't that why update-instance-for-redefined-class exists?
rg
On Apr 22, 2013, at 1:23 PM, Pascal Costanza wrote:
> Check out AspectL, it provides exactly what you want.
>
> However, it's also worthwhile spending some time on thinking about whether there is a better design for your problem. Adding slots like this creates a lot of problems. Maybe a typical hash table based meta class already provides what you need...
>
> Pascal
>
> Sent from my iPad
>
> On 22 Apr 2013, at 19:32, Ron Garret <ron at flownet.com> wrote:
>
>> Apologies for the non-CCL-related question, but c.l.l. is slow today and I'm really stuck on this.
>>
>> I need to dynamically add a slot to a class using the MOP. There doesn't seem to be a standard add-slot method, so I figure I need to use something like ensure-class. To do that, I need to reconstruct the argument to :direct-slots from the existing class definition so I can add a slot without disturbing the existing slots. Before I went down this rabbit hole I thought I'd ask: is there a better/easier way to do this? Surely I'm not the first person to want to do this.
>>
>> Many thanks,
>> rg
>>
>> _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> http://clozure.com/mailman/listinfo/openmcl-devel
More information about the Openmcl-devel
mailing list