方案错误:执行:未绑定符号:“错误" [英] Scheme Error: execute: unbound symbol: "error"

查看:43
本文介绍了方案错误:执行:未绑定符号:“错误"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学校学习 Scheme 语言并尝试使用 error 函数来处理极端情况.当我尝试类似问题中的这段代码时,我得到了一个error Error: execute: unbound symbol: "error" [in?] 而不是打印出错误信息.

I am learning Scheme language in school and trying to use error function to handle corner cases. When I try this code from a similar question, I got an error Error: execute: unbound symbol: "error" [in?] instead of printing out the error message.

这是上面链接中的示例代码:

This is the example code from the link above:

(define in? 
  (lambda (el lst)
    (if (or (null? lst) (pair? lst))
        (if (null? lst) 
            #f
            (if (equal? (car lst) el )
                #t
                (in? el (cdr lst))))
        (error "ERROR"))))

输入和输出应该是这样的:

The input and output should be like:

(in? 1 '(2 5 3))
=> #f
(in? 3 '(2 5 3))
=> #t
(in? 1 5)
=> ERROR

但是,我得到:

(in? 1 5)
Error: execute: unbound symbol: "error" [in?]

我正在使用 repl.it 在线编译器来编译 Scheme 代码.有人知道为什么没有定义错误函数吗?我想定义我自己的错误函数吗?如果是这样,谁能给我一个简单的例子来展示编写错误函数的基本风格?我从 MIT Scheme Error 中阅读了参考资料系统,但我觉得很失落.

I am using repl.it online compiler to compile the Scheme code. Anyone know why is the error function not definded? Do I suppose to define my own error function? If so, could anyone give me a simple example to show the basic style of writing an error function? I read the reference from MIT Scheme Error System but I feel lost.

推荐答案

就 Scheme 标准而言,没有称为 error 的过程或特殊形式.我已经在 MIT Scheme 中尝试过它并且确实它被定义并且在使用时发出错误信号但是在 repl.it 中,Scheme 实现被称为 BiwaScheme 并且它与 MIT Scheme 锁定不兼容.

As far as the Scheme standard goes there is no procedure or special form called error. I've tried it in MIT Scheme and sure enough it is defined and when used signals an error but in repl.it the Scheme implementation is called BiwaScheme and it isn't compatible with MIT Scheme lock in.

BiwaScheme 似乎不完全支持任何 Scheme 标准 所以我不会建议你使用它(还).

BiwaScheme doesn't seem to fully support any Scheme standard so I would not suggest you use it (yet).

我强烈建议您在学习 Scheme 时使用与当前标准之一兼容的 Scheme 实现.

I strongly suggest you use a compatible Scheme implementation to one of the current standards when learning Scheme.

这篇关于方案错误:执行:未绑定符号:“错误"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆