Thread View: comp.lang.clos
1 messages
1 total messages
Started by Hallvard Tr{tteberg
Thu, 12 Nov 1992 01:20
setf methods
Author: Hallvard Tr{tteberg
Date: Thu, 12 Nov 1992 01:20
Date: Thu, 12 Nov 1992 01:20
48 lines
2713 bytes
2713 bytes
Hi Lispers, When I learned about object oriented programming one of the views that was taught was that the set of methods of a class should preserve a set of invariants related to the class. I.e. the object state before and after a (official or exported) method is run should satisfy a set of constraints, which of course could be violated while running the method. I like this view, since it defines clearly the responsibility of the method writer with respect to the method user. With CLOS the methods don't belong to a class but I think the view could be adopted, especially in the non-multi method case. E.g. if a slot has an accessor before/after and around methods could be used for ensuring that constraints are satisfied. However, there are often inter-class constraints that needs to be preserved. In my graph editor application, each node has an out-edges slot with a list of edges and each edge has a from-node slot which point back. A constraint for the node-edge relation could be formulated as: (member edge (out-edges node)) <=> (eq (from-node edge) node), which means that whenever an edge is in the out-edges list of a node, the from-node slot of edge should point to this node. I have written a macro, define-slot-relation, that expands such a constraint into two setf-around-methods, one for each slot. My question is whether it's best to generate setf-around-methods to take care of such a constraint, or should I make another layer of methods, e.g. set-node-out-edges and set-edge-from-node. Personally, I prefer using setf-methods, if they shouldn't be used for such things what should they be used for? In addition, we already have a layer below, (setf slot-value). A problem I see, is that the user of the setf-method perhaps expects the implementation to have low computational complexity e.g. O(1) instead of my O(n). Anyway, I have discussed this with my colleagues and we don't agree, so I thought I'd ask other lispers for their opinion. Regards, Hallvard -- Hallvard Traetteberg Dept. of Knowledge Based Systems Center for Industrial Research Box 124 Blindern, 0314 Oslo 3 NORWAY Tlf: +47 2 45 29 83 or +47 2 45 20 10 Fax: +47 2 45 20 40 Email: Hallvard.Tretteberg@si.no
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads