简体   繁体   English

R5RS中未定义的ADT

[英]Undefined ADT in r5rs

I'm writing an ADT in r5rs and I'm using DrRacket. 我正在r5rs中编写ADT,并且正在使用DrRacket。 I put #lang r5rs at the top of my file and chose Determine Language from Source from DrRacket, but it tells me my ADT is undefined. 我将#lang r5rs放在文件的顶部,并从DrRacket中选择“ 从源代码确定语言” ,但这告诉我ADT未定义。 I'm using DrRacket version 6.0. 我正在使用DrRacket 6.0版。 It's the first time I've had this and can't understand what I'm doing wrong. 这是我第一次遇到这种情况,无法理解我做错了什么。

My ADT 我的ADT

#lang r5rs
(#%require "queue.rkt") ;A required file
(#%provide (all-defined))

(define (my-ADT)
    (let ((val1 '())
          (val2 '()))

    (define (foo) ...)
    (define (bar) ...)

    (define (dispatch msg)
        (case msg
            ((foo) foo)
            ((bar) bar)
            (else "Unknown message")))

    dispatch))

When I try to create an instance of my-ADT I get the following output: my-ADT: undefined; cannot reference an identifier before its definition 当我尝试创建my-ADT的实例时,得到以下输出: my-ADT: undefined; cannot reference an identifier before its definition my-ADT: undefined; cannot reference an identifier before its definition

When I remove #lang r5rs from the top and choose R5RS as language in DrRacket, it seems to work. 当我从顶部删除#lang r5rs并在DrRacket中选择R5RS作为语言时,它似乎可以工作。 But then my queue.rkt file still has #lang r5rs at the top and Determine Language from Source . 但是然后我的queue.rkt文件仍然在顶部具有#lang r5rs从Source中确定Language When I remote #lang r5rs and choose R5RS as language in that file also, I get the following in the my-ADT file: 当我远程#lang r5rs并在该文件中还选择R5RS作为语言时,在my-ADT文件中得到以下内容:

default-load-handler: expected a `module' declaration
found: something else
in: #<path:/Users/path/path/path/queue.rkt>

The error 错误

my-ADT: undefined; my-ADT:未定义; cannot reference an identifier before its definition 无法在定义标识符之前引用标识符

normally indicates that the function my-ADT was used before it was defined. 通常表示函数my-ADT在定义之前就已使用。 That is, one must place all definitions on top of the file and place the expressions below. 也就是说,必须将所有定义放在文件顶部,并将表达式放在下面。

Your example above has no uses of my-ADT so if you get this error, the problem might be in "queue.rkt". 上面的示例没有使用my-ADT因此,如果出现此错误,则问题可能出在“ queue.rkt”中。 Can you run "queue.rkt" without errors? 您可以正确运行“ queue.rkt”吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM