The "wrong list" error in the DrRacket spelling scheme

I just follow the instructions in 3.3.3 SICP to create the table. The code I wrote works well.

here is code_0.scm:

#lang scheme

(require rnrs/base-6)
(require rnrs/mutable-pairs-6)

(define (make-table)
  (list '*table*))

(define (assoc key records)
  (cond ((null? records)
         false)
        ((equal? key (caar records))
         (car records))
        (else
         (assoc key (cdr records)))))

(define (insert! key value table)
  (let ((record (assoc key (cdr table))))
    (if record
        (set-cdr! record value)
        (set-cdr! table
                  (cons (cons key value)
                        (cdr table)))))
  'OK)

(define (lookup key table)
  (let ((record (assoc key (cdr table))))
    (if record
        (cdr record)
        false)))


(define table (make-table))

(insert! 0 0 table)
(insert! 1 1 table)
(insert! 2 2 table)

      

Also, I want to reference the table as a library in another file, so I write code_1.scm.

; plus: I am removing the "# lang schema" in code_0 for the time being

code_1.scm:

#lang scheme/load
(load "code_0.scm")

(define table-0 (make-table))

(insert! 0 0 table-0)
(insert! 1 1 table-0)
(insert! 2 2 table-0)

      

Compilation error:

assoc: invalid list: {{0. 0}}

What happened to all this?

Its about LIST in Scheme, DrRacket issue or language version / standard?

+1


source to share


1 answer


The problem is what assoc

is the existing function in the schema. Try renaming the function to my-assoc and it will work as expected.



+2


source







All Articles