Rahn
Rahn

Reputation: 5405

"not a proper list" error in DrRacket writing Scheme

I just follow the instructions at 3.3.3 of SICP to create the table. The code I wrote just 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)

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

;plus: I delete the "#lang scheme" in code_0 at this time

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)

compiling error shows:

assoc: not a proper list: {{0 . 0}}

What's wrong with all of this?

Its about LIST in the Scheme, problem of DrRacket, or the version/standard of language?

Upvotes: 1

Views: 958

Answers (1)

vukung
vukung

Reputation: 1884

The problem is that assoc is an existing function in scheme. Try renaming the function to my-assoc, and it will work as expected.

Upvotes: 2

Related Questions