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

RE: Implementing 2d-put! and 2d-get in DrScheme



You can get the basic functionality of prop2d.scm working under DrScheme as
follows:

1.  Remove the line which reads (declare (usual-integrations))

2.  Add the following stubs:

	; stubs for DrScheme
	(define (object-hash x) x)
	(define (object-unhash x) x)
	(define (valid-hash-number? x) #t)

3.  Change the definition of initialize-package! to look like this:

	(define (initialize-package!)
	  (set! system-properties '()))

4.  Provide a value for the three defines that have no value and cause
errors under DrScheme:

	(define system-properties '())
	(define delete-invalid-hash-numbers! '())
	(define delete-invalid-y! '())

This now works well enough that the following far-from-comprehensive test
program gives the expected results:

	(2D-put! 5 9 3)
	(2D-put! 5 12 7)
	(2D-get 5 9)
	(2D-get 5 12)
	(2D-get-alist-x 5)
	(2D-get-alist-y 9)
	(2D-put! 'foo 'gaga 'a)
	(2D-put! 'foo 'googoo 'b)
	(2D-get 'foo 'gaga)
	(2D-get-alist-x 'foo)

The code that has been stubbed out has to do with implementing weak
references under MIT Scheme, using association lists.  If you don't require
the weak reference functionality - i.e. if you don't care whether data
builds up in this structure, or if you plan to remove unused elements
yourself - then the stubs I've provided above should be perfectly adequate.
You could even simplify the code a bit by removing the calls to the stubs.

However, if you do need weak reference behavior, then your best bet would be
to rewrite the routines using DrScheme weak hash tables (see
make-hash-table-weak).  This would be fairly easy, and would involve less
code than the MIT Scheme version, since you wouldn't have to handle the weak
references yourself.

Anton