Lisp:我如何获取在initialize-instance :around方法中创建的实例
我想为类 X 创建一个初始化实例的 (:around Qualified) 专门化器,它将首先调用下一个方法,然后调用另一个类的 make-instance,为其提供创建的 X 实例。我怎样才能获取在initialize-instance :around 方法中创建的实例? (当然假设在调用了 call-next-method 之后,所以我们处于 :around 的完成端)
编辑: A 类与 B 类通过每个类中的一个槽保持另一个类的 id,具有双向关系,但 A 类需要 B 类的 id,而相反则不需要。所以我想要的流程是:
- make-instance 'classA
inside initialize-instance :around classA 我会有:
我。 make-instance classB 并获取 id-of-B。
ii 调用下一个方法添加 id-of-B
iii 将 classB 的相应 id-of-A 插槽设置为我们创建的 classA 实例(这是我最初的问题原因)
现在我可以在 :before 和 [ 中执行 [i] iii] 在:之后,但我不能: 类 A 和 B 是通过大象的持久类,我想将整个流程包装在一个事务中,我不想跨越许多方法。对于那些熟悉大象的人来说,我想使用确保事务包装器,并且我不想在不同的点使用显式的开始和提交函数调用。
I want to create an (:around qualified) specializer of initialize-instance for a class X that will first call-next-method and then will call make-instance of another class, supplying it with the created instance of X. How can i get hold of the created instance inside initialize-instance :around method? (assuming of course after having called call-next-method so we are at the finilizing side of :around)
EDIT:
Class A has a bi-directional relationship with Class B through a slot in each one that keeps the id of the other, but class A requires id of class B, while the opposite is not required. So the flow i want is:
- make-instance 'classA
inside initialize-instance :around classA I would have:
i. make-instance classB and aquire id-of-B.
ii call-next-method adding id-of-B
iii set the corresponding id-of-A slot of classB point to our created classA instance (this is my original question reason)
Now I could do [i] in :before and [iii] in :after, but i cant:
Classes A and B are persistent classes through elephant and I want to wrap the whole flow in a transaction which I wouldnt like to span many methods. For those familiar with elephant, I want to use ensure-transaction wrapper, and I dont want to use explicit begin and commit function calls in different points.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该实例作为
initialize-instance
的第一个参数传递。The instance is passed as the first argument of
initialize-instance
.您通常会使用
:after
方法而不是:around
方法来执行此操作。除非您深入研究 CLOS 的内部,否则对未初始化的实例执行任何操作都没有多大意义。该实例作为initialize-instance
的第一个参数提供。如需更深入的处理,请参阅CLHS,第 7.1 节。
You would usually do that with an
:after
method, not an:around
method. Unless you fiddle around deeply in the guts of CLOS, it does not make much sense to do anything with an uninitialized instance. The instance is supplied as the first argument ofinitialize-instance
.For a deeper treatment, look at the CLHS, section 7.1.