🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.clos
Article #296

setf methods

#296
From: Hallvard Tr{tteberg
Date: Thu, 12 Nov 1992 01:20
48 lines
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
Technical Details
Message-ID: <HALTRAET.92Nov12022039@monsun.si.no>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!ugle.unit.no!nuug!ifi.uio.no!si.no!fenrix.si.no!haltraet

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.clos,comp.lang.lisp
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!ugle.unit.no!nuug!ifi.uio.no!si.no!fenrix.si.no!haltraet
From: haltraet@monsun.si.no (Hallvard Tr{tteberg)
Subject: setf methods
Sender: usenet@si.no (News Poster)
Message-ID: <HALTRAET.92Nov12022039@monsun.si.no>
Date: Thu, 12 Nov 1992 01:20:39 GMT
Nntp-Posting-Host: monsun.si.no
Organization: Center for Industrial Research, Dept. of Knowledge Based Systems
Lines: 48