如何调试station中的scheme
我发现自己经常想要检查语句并打印出那里发生的事情。例如,使用此基本示例:如何调试station中的scheme,scheme,lisp,sicp,Scheme,Lisp,Sicp,我发现自己经常想要检查语句并打印出那里发生的事情。例如,使用此基本示例: (define (example-debug lst) (if (null? lst) '() (example-debug (cdr lst)))) (example-debug '(1 2 3)) 如何在if语句的两个部分中显示?以python为例,我可能会有如下内容: def example_debug(lst): if not lst: print (&quo
(define (example-debug lst)
(if (null? lst)
'()
(example-debug (cdr lst))))
(example-debug '(1 2 3))
如何在if
语句的两个部分中显示?以python为例,我可能会有如下内容:
def example_debug(lst):
if not lst:
print ("End of list reached")
else:
print ("Element is: %s" % lst[0])
example_debug(lst[1:])
是否有一个干净的ish或类似的方式来实现上述计划?非平凡的程序通常是如何“调试”的?如果使用打印语句调试
,则会很麻烦,因为您不能为结果或替代语句编写多个表达式,如果您想做多件事,则必须使用开始(我使用的是专门针对Racket的printf
,请根据您的口译员进行调整):
如果使用cond
,它的可读性会稍高一些,该cond具有隐式begin
s:
(define (example-debug lst)
(cond ((null? lst)
(printf "End of list reached~n")
'())
(else
(printf "Element is: ~a~n" (first lst))
(example-debug (cdr lst)))))
但要真正回答您的问题:不要使用打印来调试:)。一个好的IDE(比如Racket)有一个内置的调试器。谢谢你的帮助。什么是printf
(我假设像C)?在使用#lang sicp
时,我没有将其作为一个内置程序。还有,我在用球拍。关于如何使用调试器查看值的任何好的教程或示例?printf
有点像C的简化版本,可以在#lang racket
中找到。对于#lang sicp
,您可以使用显示
。看一看关于调试器的示例。
(define (example-debug lst)
(cond ((null? lst)
(printf "End of list reached~n")
'())
(else
(printf "Element is: ~a~n" (first lst))
(example-debug (cdr lst)))))