我有以下代码:
(define (eval-1 exp)
; display expressions added. -- dlb
(display "Executing eval-1, exp = ")
(displayln exp)
(cond ((constant? exp)
(displayln "constant? is true")
exp)
((symbol? exp)
(displayln "symbol? is true")
(eval exp)) ; use underlying Racket's EVAL
((quote-exp? exp) ; *CHANGE* Modified to check if the length of the input is 2 as 2 inputs is only 1 value and an expression.
(if (= (length exp) 2)
(begin
(displayln "quote? is true")
(cadr exp))
(error "Quote expression must have exactly one argument"))) ; *CHANGE* Throw an error and terminate if more than 1 value is input.
((if-exp? exp)
(displayln "if-exp? is true")
(if (eval-1 (cadr exp)) ; use underlying Racket's IF
(eval-1 (caddr exp))
(eval-1 (cadddr exp))))
((lambda-exp? exp)
(displayln "lambda-exp? is true")
exp)
((map-exp? exp)
(displayln "map-exp? is true")
(apply-1 (eval-1 (cadr exp)) (map eval-1 (cddr exp))));add in (map-1 (lambda (x) (* x x)) '(1 2 3 4))
((pair? exp)
(displayln "pair? is true")
(apply-1 (eval-1 (car exp)) ; eval the operator
(map eval-1 (cdr exp))))
(else (error "bad expr: " exp))))
它在一个临时方案解释器中,定义为 (define (eval-1 exp) 处理诸如 lambda、if 等的事情。我还有一个帮助器可以识别何时输入 map-1 命令。我的 map-1当我输入“(map-1 + '(1 2 3 4) '(10 20 30 40))”以及每当我尝试输入像“(map-1 (lambda (x) (*) x x)) '(1 2 3 4))" 我总是遇到违反合同的情况,我不确定如何做到这一点,以便这两个测试用例都能通过。
我尝试单独使用 map 以及添加 apply map,发现 apply map 可以处理值,但不能处理 lambdas。
• 初学者编码作业,我不断收到“预期标识符或”(“,这是什么意思,我该如何解决?[关闭]
• 颤动错误:com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
• 错误:迁移遗留应用程序时,在工作区外运行 Angular CLI 时,此命令不可用
• 用于发送 SMS 的 Twilio API 在本地有效,但部署到 Netflify 时无效
• 我正在尝试将 firebase 实施到我的 maui.net 应用程序中,但遇到了 FirebaseAuthProvider 问题
• 使用 .war 将 SpringBoot 应用程序部署到 ec2,出现 404 错误
• CORS 配置不工作 Spring WebFlux 应用程序
• 有没有办法手动解锁 Opentext Exstream 设计数据库?
• 我在为我的vue项目服务时,在manifest json中得到一个错误,我无法定位。