“not a proper list” error in DrRacket writing Scheme

孤者浪人 提交于 2019-12-11 13:59:04

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/31602788/not-a-proper-list-error-in-drracket-writing-scheme

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!