OUCH!!! As Tze-Yun and Josh pointed out to me tonight, the ps 5 solutions are
incomplete. Specifically, problem 5 omitted solutions for RECORD-INSERT and
RECORD-DELETE. This revealed a small bug which nonetheless makes defining
RECORD-DELETE insufferable. The small fix to this small bug makes RECORD-DELETE
fairly straightforward. Read on...


Here are the ideas:

To (RECORD-INSERT name file identifier info) we must:
 1) Define a generic MAKE-FILE-RECORD
 2) Use it to INSERT the indentifier/info record into the file for name.

To (DELETE-RECORD name file identifier) we must:
 1) LOOKUP the record for NAME in FILE
 2) DELETE the IDENTIFIER entry from that record
 3) Take the resulting record and re-INSERT it into the file for name, where
    the file re-INSERTed into is the original file minus the entire entry for
    name. Of course, if the resulting record was empty then just return the
    file minus the entire entry for name. 

Here is the code... [CAVEAT: I have not run this. I'll run it tomorrow AM]

==============================================================================
(define (make-file-record file id info)
  (let ((type (header file)))
    (let ((make-record (cond ((eq? type 'big-aqua) make-record-table)
			     ((eq? type 'quince  ) make-record-table)
			     ((eq? type 'helios  ) make-record-tree )
			     (else (error "Unrecognized file type" type)))))
      (make-record id info))))

(define (insert-record name file identifier info)
  (insert name (make-file-record identifier info) file))

(define (delete-record name file identifier)
  (let ((old-record (lookup name file)))
    (if (empty? old-record)
	file
	(let ((del-record (delete identifier (attach (header file)
						     (info old-record)))))
	  (if (or (empty? (info del-record))
		  (bare?  (info del-record)))
	      (delete name file)
	      (insert name (info del-record) (delete name file)))))))
==============================================================================

***********
* BUG FIX *  (define (record-tree? obj) (branch? obj))
***********

I.e., the old definition of RECORD-TREE? was too rigid. IT would never have
allowed the INSERT of (INFO DEL-RECORD) above. I'll place this on the lab
blackboard, patch all the on-line copies of ps5 code and email it to Athena
hackers. Sorry!!!!!!

Please notice that this bug reveals itself only for RECORD-DELETE, which is
easy with the fix but very tedious and hairy without it. Perhaps we should be
very lenient in grading this single isolated procedure. It is used nowhere else
in the problem set. Of course, I blame only myself.  (I never caught this
because I never had any RECORD-DELETE to test. This oversight hurts deeply.)

 Mortified, humbled and humiliated,
     ziggy
