From @life.ai.mit.edu:ziggy@hx.lcs.mit.edu Wed Oct 16 22:55:07 1991
Received: by hx.LCS.MIT.EDU (5.51/4.7); Wed, 16 Oct 91 22:55:04 EDT
Received: from life.ai.mit.edu by mintaka.lcs.mit.edu id aa16023;
          16 Oct 91 22:54 EDT
Received: from hx.LCS.MIT.EDU by life.ai.mit.edu (4.1/AI-4.10) id AA27683; Wed, 16 Oct 91 22:51:57 EDT
Received: by hx.LCS.MIT.EDU (5.51/4.7); Wed, 16 Oct 91 22:51:48 EDT
Date: Wed, 16 Oct 91 22:51:48 EDT
From: "Michael R. Blair" <ziggy@hx.lcs.mit.edu>
Message-Id: <9110170251.AA15636@hx.LCS.MIT.EDU>
To: 6001-staff@ai.mit.edu
Subject: PS5 is NOT broken
Status: R

There has been some concern raised about PS5. I have carefully reviewed the
points you have all raised (thanks for raising them!) and I have concluded that
the problem set is indeed too tacit on the topic of recursive structures, but
this can be easily remedied. It is also tacit on a point of style. Let me take
these points in turn then summarize.

------------------------------------------------------------------------------

First, Julie raised an important point about style. Nowhere do we say what must
happen if you attempt to insert a record which already has an entry in a
database. HOWEVER, the existing code (both INSERT-UNORDERED and INSERT-TREE)
handle this in a similar way.  Specifically, if the new entry and the old entry
are themselves records then they are merged. IF not, the old one is added in a
way which shadows the old. This is all addressed in the solutions that Bob
Berwick and I prepared. This is why we ask the students explicitly to describe
in English what happens when an insert is done in TREEs.

It is reasonable for the students to recognize that this is also what happens
for UNORDERED records and to infer from this that their code should do the
same. It is important for students to realize that when adding code to a system
they should try to make it consistent with the style of the existing code.
Perhaps this should be stated explicitly in the problem set? Anyone care to
argue the point?

------------------------------------------------------------------------------

Second, Tze-Yun raised an important point about the recursive data structure of
records. I admit I should have encouraged people to try the following test
case:

==============================================================================
(define (test-rec-struct)
 (insert-ordered 'jane
                 (make-record-table 'nickname
                                    (make-record-table 'home 'sis))
                 (insert-ordered 'jane
                                 (make-record-table 'nickname
                                                    (make-record-table 'mit
                                                                       'janey))
                                 quince)))
==> (test-rec-struct)
(QUINCE (JANE (ADDRESS 350 MEMORIAL DR)
              (NICKNAME (HOME . SIS) (MIT . JANEY))
              (SALARY . 64000))
        (RUTH (ADDRESS 90 SUMMER ST)))
==============================================================================

I will email this to hackers on Athena and will post it on the black board in
the 6.001 lab tonight. Perhaps we should discuss a grading policy for this
problem in light of the late notice of this test case to the students.  It is
not a crucial issue but one that I will certainly avoid (i.e.  fix) for future
terms.

Anyway, this directly addresses the point Tze-Yun raised.  Specifically...  her
suggested alternative solution to INSERT-ORDERED...

==============================================================================

(define (insert-ordered name record file)
  (define (insert-aux name record records)
    (let ((folder (attach name record)))	;; **
      (cond ((empty? records)
	     (attach folder records))
	    ((eq? (id (curr-folder records)) name)
	     (let ((curr-info (info (curr-folder records))))
	       (let ((new-info (if (and (record-table? curr-info)
					(table-header? (body record)))
				   ;; Recursive file structure
				   (insert-aux (id (body record))
					       (info (body record))
					       curr-info)
				   (append-ordered (body record) curr-info))))
		 (let ((new-folder (attach name new-info)))		;; **
		   (attach new-folder (rest-folders records))))))	;; **
	    (else (append-ordered folder records)))))			;; **
  (if (table-header? file)
      (if (record-table? record)
	  (attach (header file)
		  (insert-aux name record (folders file)))
	  (error "INSERT-ORDERED: record was not created by MAKE-RECORD-TABLE" record))
      (error "INSERT-ORDERED: file must be a table header" file)))

==============================================================================

This does not maintain the recursive structure of the records. For example,
consider that in the example database for Quince, JANE has an ADDRESS entry.
Now what should happen if we insert a new ADDRESS entry. The result your code
produces is not the same as the result my code produces. If it helps you to
think about this: imagine the existing entry were (ADDRESS (HOME 350 MEM DR))
and the new entry is (ADDRESS (WORK 545 TECH SQ)). The resulting entry should
then be (ADDRESS (HOME ...)(WORK ...)). Your solution does not produce that.

[Tze-Yun: On your second point: indeed, the last example in the ps1 solutions
should have used INSERT-ORDERED rather than just INSERT. Thanks!]

------------------------------------------------------------------------------

Again, I confess that I should have provided a sample database that would raise
precisely this point. I will fix it for future terms.

I dont think anyone would be confused if they thought carefully about the style
of the existing code (namely, INSERT-UNORDERED) and modeled their solution
after it. Although I clearly need to make this point more clear in the problem
set, it is not that large a leap of faith for a student to make.  I think
nobody has quite understood or appreciated the point about these records being
recursively structured. Think about polynomials whose coeffs can be polys etc
from the generic arithmetic lecture. IF a student seems confused, tell them to
think about that lecture again.

I apologize for the vagueness of the problem set but I dont think this issue
warrants an addendum other than the above mentioned test case. I think we
can help people as their needs demand. I especially dont want to hear that any-
one is saying to the students ``yeah, this problem set is broken'' It is not.
I will be very miffed if such a demoralizing rumor gets started. It REALLY
pisses off the students.

*******************************************************************************
IT HAS ALSO BEEN SUGGESTED THAT MANY STUDENTS ARE GETTING CONFUSED BECAUSE THEY
ARE LOOKING AT THE ON-LINE ARCHIVED SOLUTIONS ON ATHENA TO A PREVIOUS TERMS
BROKEN VERSION OF THIS PROBLEM SET AND ITS BROKEN SOLUTIONS. THEY GET WHAT THEY
DESERVE. DONT LET THEM CONFUSE YOU JUST BECAUSE THEY ARE CONFUSED. THINK ABOUT
THE PROBLEM SET.  CAVEAT EMPTOR AD INFINITUM DUDES!!!
*******************************************************************************

