簡體   English   中英

小策划人德拉克雷特錯誤無法在定義標識符之前引用標識符

[英]little schemer drracket error cannot reference an identifier before its definition

初學者的問題,剛開始讀小計划書,並在我的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))) 

有人知道我做錯了嗎?

謝謝

看起來最后一次通話應該是

(lat? '(a b))

...不?

(另外:我一般建議使用#lang球拍,但是我強烈懷疑出現問題R5RS是因為您“兩次設置語言”;如果您使用#lang R5RS啟動程序,則無需更改相反,如果設置了語言級別,則不應使用#lang R5RS啟動程序。如果兩者都執行,我猜您會收到看到的錯誤消息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM