[plt-scheme] can't run SICP "generic operations" code in PLT Scheme 4.1
You could write this even more simply as:
(define (make-table)
(let ([ht (make-hash)])
(values
(λ (k1 k2) (hash-ref ht (list k1 k2) #f))
(λ (k1 k2 v) (hash-set! ht (list k1 k2) v)))))
(define-values (get put) (make-table2))
Or, if you actually wanted to use objects, you'd write something like this:
(define table%
(class object%
(define local-table (make-hash))
(define/public (get k1 k2)
(hash-ref local-table (list k1 k2) #f))
(define/public (put k1 k2 v)
(hash-set! local-table (list k1 k2) v))
(super-new)))
(define operation-table (new table%))
(define (get k1 k2) (send operation-table get k1 k2))
(define (put k1 k2 v) (send operation-table put k1 k2 v))
Robby
On Wed, Oct 15, 2008 at 6:21 PM, Fred G. Martin <fredm at cs.uml.edu> wrote:
> Hey, I rewrote the make-table routine using the hash procedures, and
> it is definitely happier! See below.
>
> Thanks too for the pointer to that Version 4.x FAQ. It is long, but
> clearly discussing the critical issues in a concise fashion. A big
> help.
>
> Fred
>
> ;SICP generic operations table re-written with hash
> (define (make-table)
> (let ((local-table (make-hash)))
> (define (lookup key-1 key-2)
> (hash-ref local-table (list key-1 key-2) #f))
> (define (insert! key-1 key-2 value)
> (hash-set! local-table (list key-1 key-2) value)
> 'ok)
> (define (dispatch m)
> (cond ((eq? m 'lookup-proc) lookup)
> ((eq? m 'insert-proc!) insert!)
> (else (error "Unknown operation -- TABLE" m))))
> dispatch))
>
> (define operation-table (make-table))
> (define get (operation-table 'lookup-proc))
> (define put (operation-table 'insert-proc!))
>
>
>
> On Wed, Oct 15, 2008 at 8:32 AM, Robby Findler <robby at cs.uchicago.edu> wrote:
>> On Wed, Oct 15, 2008 at 7:23 AM, Matt Jadud <jadudm at gmail.com> wrote:
>>> For Fred (and others coming to the PLT 4.x game late), the things that
>>> took me by surprise yesterday:
>>>
>>> 1. Hash table operations have all had name changes.
>>> A. Mutators are gone from structures. (define-struct foo (a b)) no
>>> longer yields "set-foo-a!". Yes, they can be introduced at
>>> definition-time, but not if they're being provided by a library.
>>> "struct-copy", I think, was the functional way to update a structure.
>>> (Apologies if I just got that wrong.)
>>
>> Yes, struct-copy (note that copy-struct is the old one).
>>
>>> 2. 'require' and 'provide' specifications have changed.
>>
>> Just in case you didn't find it yet, more along the lines of the above
>> can be found in the plt distribution:
>>
>> plt/doc/release-notes/mzscheme/MzScheme_4.txt
>>
>> The latest version of that file is here:
>>
>> http://svn.plt-scheme.org/plt/trunk/doc/release-notes/mzscheme/MzScheme_4.txt
>>
>> Robby
>>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>