Lisp Signatures...
Here is a simple example of what I'm referring to. The stuff mentioned from Tobias is very close, if perhaps a little too elaborate. I just finished hacking an example, now that I have seen some of the offerings and I gained a better image in my mind of what I needed:Example protocol specification:
(protocol:define-protocol btree-protocol (btree node)
(:type
(height integer)
(index integer)
(count integer))
(:signature
( node-height (node) => height)
( node-fill-pointer (node) => index)
( (setf node-fill-pointer) (index node) => index)
( node-list-cell (node index) => t)
( (setf node-list-cell) (t node index) => t)
( node-capacity (node) => count)
( copy-node-list-cells (node index node index count) => nil)
( root-node (btree) => node)
( (setf root-node) (node btree) => node)
( items-count (btree) => count)
( (setf items-count) (count btree) => count)
( compare-fn (btree) => function)
( key-fn (btree) => function)
( make-node (btree height) => node)
( discard-node (btree node) => nil)
))
;; --------------------------------------------------------------------------------------
;; Define all the methods here...
....
;; --------------------------------------
;; After methods have been defined...
(protocol:implements-protocol btree-protocol (file-btree file-node))
;; --------------------------------------
The protocol specification names the protocol, here btree-protocol, and the parameters are the names of types (classes) that will parameterize the protocol specification. Below that introduction we have two optional groups. The first one named :TYPE allows the introduction of named types to help clear up the intent and meaning of the following signatures. The :SIGNATURE section names a bunch of methods, their argument types, and the bit "=> type" is just for decoration at this time.
Then later, after the methods have actually been defined, I attempt to state that the methods that I have just defined satisfy the btree-protocol, with actual classes named FILE-BTREE and FILE-NODE as parametric types for the protocol. This causes the system to run through the protocol signatures and verify that indeed there are methods with those stated signatures, and using the concrete types FILE-BTREE and FILE-NODE. If not, then an error message is printed and the loading halts.
All of this was accomplished in about 100 LOC, including comments and whitespace...
Dr. David McClain
Chief Technical Officer
Refined Audiometrics Laboratory
4391 N. Camino Ferreo
Tucson, AZ 85750
email: dbm@refined-audiometrics.com
phone: 1.520.390.3995