[plt-scheme] can't run SICP "generic operations" code in PLT Scheme 4.1
Did you consider make-hash, hash-get, and hash-set! and friends?
Robby
On Tue, Oct 14, 2008 at 11:33 PM, Fred G. Martin <fredm at cs.uml.edu> wrote:
> Mmm OK, I modified the make-table procedure to use mutable-pairs and
> lists, and it works now.
>
> I also found the nice blog entry about why mutable pairs (at least the
> default ones) are bad --
> http://blog.plt-scheme.org/2007/11/getting-rid-of-set-car-and-set-cdr.html.
>
> Is this code really the right way to go? Or is there a much simpler
> (built-in?) version of this? (code below).
>
> Fred
>
>
> (define (make-table)
> (let ((local-table (mlist '*table*)))
> (define (lookup key-1 key-2)
> (let ((subtable (massoc key-1 (mcdr local-table))))
> (if subtable
> (let ((record (massoc key-2 (mcdr subtable))))
> (if record
> (mcdr record)
> #f))
> #f)))
> (define (insert! key-1 key-2 value)
> (let ((subtable (massoc key-1 (mcdr local-table))))
> (if subtable
> (let ((record (massoc key-2 (mcdr subtable))))
> (if record
> (set-mcdr! record value)
> (set-mcdr! subtable
> (mcons (mcons key-2 value)
> (mcdr subtable)))))
> (set-mcdr! local-table
> (mcons (mlist key-1
> (mcons key-2 value))
> (mcdr local-table)))))
> '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 Tue, Oct 14, 2008 at 11:19 PM, Woodhouse Gregory
> <gregory.woodhouse at gmail.com> wrote:
>> Since pairs are no longer mutable in PLT Scheme, you can't use set-cdr! You
>> probably want to use mutable pairs instead.
>>
>>
>> "The art of asking the right questions in mathematics is more important than
>> the art of solving them."
>> --Georg Cantor
>> http://www.gwoodhouse.com
>> http://GregWoodhouse.ImageKind.com
>>
>>
>>
>>
>> On Oct 14, 2008, at 7:59 PM, Fred G. Martin wrote:
>>
>> Hey all,
>> I can't figure out which language pack/ include statement / other
>> setting is necessary to run the generic operations package from SICP.
>> Here are two samples of the code I'm trying to run:
>> http://www.cs.uml.edu/~holly/91.301/ps6-code.ss
>> http://rlai.cs.ualberta.ca/325assignment5.html
>> The code works fine in PLT-Scheme 3.72 (setting "Textual (MzScheme,
>> includes R5RS)" but I am stumped trying to get it to run in 4.1.
>> In general 4.1 seems to not like redefining stuff... I must admit I am
>> mystified by all the language choices.
>> Thanks for your help,
>> Fred
>> _________________________________________________
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>