【发布时间】:2014-04-20 17:44:02
【问题描述】:
(define (walk-list lst fun) ;;walk-list(list, fun)
(if (not(null? lst)) ;;IF the list isn't NULL
(begin
(if (list? lst) ;;&& the list is actually a list , THEN{
(begin
(if (equal? (car lst) '()) ;;IF the first element in the list is empty
(fun lst) ;;THEN call the function on the list (funct is supose to get each word)
(if (not (null? lst)) ;;ELSE IF the first item isn't a list
(begin ;;{
(walk-list (car lst) fun) ;;walk-list((car lst),fun)
(walk-list (cdr lst) fun))))))))) ;;walk-list((cdr lst),fun)
(walk-list test-document display) ;;walk through the list with the given document
看起来像这样:
(define test-document '(
((h e l l o));;paragraph1
((t h i s)(i s)(t e s t));;paragraph2
))
我试图让文档中的每个单词都应用一个函数。在哪里说(有趣的清单)。但该函数永远不会被调用。
【问题讨论】:
-
你能显示对这个过程的调用和预期的输出吗?
-
函数被调用,但你没有用结果构建输出列表
-
函数打印它。我要改成显示了,还是什么都不显示。