编写方案中的错误

编写方案中的错误

本文介绍了“不是一个正确的列表"DrRacket 编写方案中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是按照 SICP 3.3.3 中的说明创建表格.我写的代码运行良好.

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

这里是 code_0.scm:

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)

另外,我想在其他文件中将该表作为库引用,所以我写了一个code_1.scm.

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

;plus:我此时删除code_0中的#lang scheme"

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

code_1.scm:

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)

编译错误显示:

assoc:不是正确的列表:{{0 .0}}

这一切有什么问题?

是关于Scheme中的LIST,是DrRacket的问题,还是语言的版本/标准?

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

推荐答案

问题是assoc是scheme中已有的函数.尝试将函数重命名为 my-assoc,它会按预期工作.

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

这篇关于“不是一个正确的列表"DrRacket 编写方案中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 11:48