实施计划中的清单 [英] Implementing has-list in scheme
本文介绍了实施计划中的清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何递归实现Scheme函数has-list,该功能测试列表是否包含其他列表作为元素.例如((has-list'(1 2 3))应该返回false,而(has-list'(1 2(3 4)5))应该返回true.
how can you implement a Scheme function has-list recursively, which tests whether a list contains other list as an element. For example (has-list '(1 2 3)) should return false, and (has-list '(1 2 (3 4) 5)) should return true.
推荐答案
如果您需要递归且不使用map进行操作:
If you need to do it recursively and without using map:
(define (has-list? lst)
(cond
((null? lst) #f)
((list? (car lst)) #t)
(else (has-list? (cdr lst)))))
这篇关于实施计划中的清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文