0

初学者问题,刚开始写小策划书,在我的macbook上安装了DrRacket来尝试一些代码示例。

如果我选择球拍语言,下面的代码

 #lang Racket

(define (atom? x)
  (and (not (pair? x)) (not (null? x))))

(atom? '()) 



(define lat?
    (lambda (l)
        (cond
            ((null? l) #t)
            ((atom? (car l)) (lat? (cdr l)) )
            (else #f))))
(lat? (a b))       

将触发错误消息:

a: unbound identifier in module in: a

如果我选择 R5RS 语言,

#lang R5RS

(define (atom? x)
  (and (not (pair? x)) (not (null? x))))

(atom? '()) 



(define lat?
    (lambda (l)
        (cond
            ((null? l) #t)
            ((atom? (car l)) (lat? (cdr l)) )
            (else #f))))
(lat? (a b))  

我收到一条错误消息:

#%plain-module-begin: illegal use (not a module body) in: (#%plain-module-begin (module configure-runtime racket/base (require r5rs/init)) (define (atom? x) (and (not (pair? x)) (not (null? x)))) (atom? (quote ())) (define lat? (lambda (l) (cond ((null? l) #t) ((atom? (car l)) (lat? (cdr l))) (else #f)))) (lat? (a b))) 

有谁知道我做错了什么?

谢谢

4

1 回答 1

2

看起来最后一次通话应该是

(lat? '(a b))

... 不?

(另外:我一般建议使用#lang racket,但我强烈怀疑你的问题R5RS出现是因为你“设置语言两次”;如果你用#lang R5RS启动你的程序,你不需要改变语言级别。相反,如果您设置语言级别,则不应使用#lang R5RS 启动程序。如果两者都这样做,我猜您会收到您看到的错误消息。)

于 2018-06-07T05:01:43.287 回答