[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

low tech MI



   From: Kent Pitman <kmp@harlequin.com>
   Date: Sat, 20 Apr 96 18:17:54 EDT

      Date: Sat, 20 Apr 1996 04:34:18 -0400
      From: Alan Bawden <Alan@lcs.mit.edu>
      I thought it was clear that I wasn't making a proposal.

   Here's a reason why I think it would be a bad proposal--perhaps a reason
   Alan was secretly thinking when he had the good sense not to propose
   this...

You guys have -almost- made me sorry I mentioned it in the first place.
Everybody please stop trying to read so much into my mention of the Emacs
Lisp condition system.  Let me try and restate my point without reference
to Emacs Lisp:

Many people are frightened by the mention of MI.  I would guess that this
fright stems from the fact that in the world of object-oriented
programming, MI remains controversial.  MI is controversial there chiefly
because it introduces a lot of complexity (both semantic and
implementational) into method lookup.

But I don't think I've seen any proposals that we do method lookup on our
conditions.  Mostly we want "MI" (or whatever you want to call it), simply
because we want a partial order on conditions.  My point was that if all
you want is a partial order, there are -lots- of ways to get one.  The
subset relation on sets is a particularly simple way.

OK, perhaps we want a little more than just a partial order.  We probably
also want conditions to have "slots" that contain values, such that every
instance under a particular point in the partial order supports particular
slots.  Anything else?  Because if that's all we need, it can still be
pretty simple.

To get a handle on the issue of -exactly- what functionality we need from
our conditions, I have included a piece of code below.  This is -not- a
specific proposal!  I don't care about the details of what arguments
individual procedures take, or any other accidental properties of how I
wrote the code -- just focus on the conditions (and condition-types) and
think about the -functionality-.  Is there anyone out there who thinks that
there is something -missing- from this picture?

(I am certain that some of you think that this is already too -much-
functionality.  Please hold off criticizing on that basis for just a bit.
I think we can all benefit from learning exactly how far we have to go
in order to satisfy the "MI" proponents.)

; ----- Begin Code -----

; *NOTE*  THIS IS NOT A SPECIFIC PROPOSAL!  *NOTE*

; The exported interface consists of the six procedures:
;  MAKE-CONDITION-TYPE
;  CONDITION-SUBTYPE?
;  MAKE-CONDITION
;  CONDITION-INSTANCE?
;  CONDITION-REF
;  CONDITION-SET!

;
; Condition Types
;

(define (make-condition-type name slot-names supertypes)
  (vector 'condition-type
	  name
	  (map (lambda (slot-name)
		 ;; The vectors made here are really
		 ;; just used as unique objects:
		 (cons slot-name (vector 'key name slot-name)))
	       slot-names)
	  supertypes))

(define (condition-type-name       type) (vector-ref type 1))
(define (condition-type-slot-keys  type) (vector-ref type 2))
(define (condition-type-supertypes type) (vector-ref type 3))

(define (condition-subtype? t1 t2)
  (or (eq? t1 t2)
      (let loop ((supertypes (condition-type-supertypes t1)))
	(and (not (null? supertypes))
	     (or (condition-subtype? (car supertypes) t2)
		 (loop (cdr supertypes)))))))

;
; Conditions
;

(define (make-condition type)
  (vector 'condition type '()))

(define (condition-type  condition) (vector-ref condition 1))
(define (condition-slots condition) (vector-ref condition 2))

(define (set-condition-slots! condition slots)
  (vector-set! condition 2 slots))

(define (condition-instance? condition type)
  (condition-subtype? (condition-type condition) type))

;
; Using Slots
;

(define (condition-slot-key condition type slot-name)
  (let ((x (assq slot-name (condition-type-slot-keys type))))
    (cond ((not (condition-instance? condition type))
	   (error "The condition isn't an instance of the type."))
	  ((not x)
	   (error "The condition type doesn't have a slot with that name."))
	  (else
	   (cdr x)))))

(define (condition-ref condition type slot-name)
  (let ((key (condition-slot-key condition type slot-name)))
    (let ((slots (condition-slots condition)))
      (let ((x (assq key slots)))
	(if (not x)
	    #F
	    (cdr x))))))

(define (condition-set! condition type slot-name value)
  (let ((key (condition-slot-key condition type slot-name)))
    (let ((slots (condition-slots condition)))
      (let ((x (assq key slots)))
	(if (not x)
	    (set-condition-slots! condition (cons (cons key value) slots))
	    (set-cdr! x value))))))

; *NOTE*  THIS IS NOT A SPECIFIC PROPOSAL!  *NOTE*

; ----- End Code -----