(define length1
(lambda (lat)
(cond
((null? lat) 0)
(else (+ 1 (length1 (cdr lat)))))))
例如:在cond
答案 0 :(得分:1)
对于常见的lisp,您可以使用(progn (...) (...) ...)
将多个表达式组合成一个。
方案中的等价物是(begin (...) (...) ...)
。
这样:
(define length1
(lambda (lat)
(cond
((null? lat) 0)
(else (begin (display "hello world") (+ 1 (length1 (cdr lat))))))))
或者你想要:
(define length1
(lambda (lat)
(cond
((null? lat) 0)
(else (let ((or-anything-else (+ 1 (length1 (cdr lat)))))
(display or-anything-else)
or-anything-else)))
这就是我的耐心耗尽。