问题
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
However, I get:
(in? 1 5)
Error: execute: unbound symbol: "error" [in?]
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.
回答1:
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 doesn't seem to fully support any Scheme standard so I would not suggest you use it (yet).
I strongly suggest you use a compatible Scheme implementation to one of the current standards when learning Scheme.
来源:https://stackoverflow.com/questions/48531674/scheme-error-execute-unbound-symbol-error