我已将此代码写在纸上,据我所知它完全正确,但是一旦我在Dr. Dr.中运行它,我就会收到错误。我认为处理解释器有一些事情要做。这段代码有什么问题?
#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)))))
答案 0 :(得分:3)
对于输出,我建议你使用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))))
这样
(compare 2 3)
=> 3 is greater than 2
(compare 3 2)
=> 3 is greater than 2
(compare 3 3)
=> 3 and 3 are equal
另外,尝试使用DrRackets reindent all 功能,并避免在自己的行上关闭括号。