Scheme 处理方案解释器的困难
我已经在纸上写了这段代码,据我所知它是完全正确的,但一旦我在Dr.Scheme中运行它,我就会得到一个错误。我认为这与翻译有关。这个代码有什么问题Scheme 处理方案解释器的困难,scheme,racket,Scheme,Racket,我已经在纸上写了这段代码,据我所知它是完全正确的,但一旦我在Dr.Scheme中运行它,我就会得到一个错误。我认为这与翻译有关。这个代码有什么问题 #lang scheme (define (compare x y) (cond ((> x y) (display '(x is greater than y))) ((< x y) (display '(y is greater than x))) (else (display '(x and y are
#lang scheme
(define (compare x y)
(cond
((> x y) (display '(x is greater than y)))
((< x y) (display '(y is greater than x)))
(else (display '(x and y are equal)))))
#lang方案
(定义(比较x和y)
(续)
((>xy)(显示(x大于y)))
((
对于输出,我建议您使用printf
:
(define (compare x y)
(cond
((> x y) (printf "~a is greater than ~a\n" x y))
((< x y) (printf "~a is greater than ~a\n" y x))
(else (printf "~a and ~a are equal\n" x y))))
另外,尝试使用DrRackets来增强所有功能,并避免在自己的行中用括号括起来。对我来说很好。您看到了什么错误消息?@uselpa如果您应用23,它将打印回它们,它将不会比较它们
(比较23)
产生(y大于x)
,这是正确的。你期望得到什么样的输出?所以你需要写(比较23)而不仅仅是23。非常感谢兄弟,我希望你把它写下来作为答案,这样我就可以把它标记为解决方案
(compare 2 3)
=> 3 is greater than 2
(compare 3 2)
=> 3 is greater than 2
(compare 3 3)
=> 3 and 3 are equal