1

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?

Rahn
  • 4,787
  • 4
  • 31
  • 57

1 Answers1

2

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

vukung
  • 1,824
  • 10
  • 23
  • It works! So the error: "func name: description" means that it would be the same problem(conflict)? – Rahn Jul 24 '15 at 07:58