未绑定的标识符球拍运营商

red*_*ent 5 racket

这是我第一次使用球拍,当我尝试评估 Dr. Racket 中的列表时,我收到一条错误消息(*:未绑定标识符;)。

#lang racket
(define (randop)
  (define x(random 3))
  (cond
    ((= x 0) '+)
    ((= x 1) '-)
    ((= x 2) '*)
   )
)

(define (randexp ht)
   (define x(random 10))
   (define y(random 10))
   (define z(randop))
  (eval (list z y x))
)

(randexp 1)
Run Code Online (Sandbox Code Playgroud)

当在控制台中执行racket时,(eval lst)工作正常,尽管当我执行此代码时,它会出现一个未绑定的标识符。任何帮助表示赞赏。

Ósc*_*pez 2

您的调用方式有问题eval,在 Racket 中您必须在文件中执行此操作:

(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))

(define (randop)
  (define x (random 3))
  (cond
    ((= x 0) '+)
    ((= x 1) '-)
    ((= x 2) '*)))

(define (randexp ht)
  (define x (random 10))
  (define y (random 10))
  (define z (randop))
  (eval (list z y x) ns))

(randexp 1)
Run Code Online (Sandbox Code Playgroud)

另外,您实际上并未使用该ht参数,请考虑将其删除。