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.
4 Answers
If your implementation has something like ormap, then:
(define (has-list? l) (ormap list? l))
Using or as in Dan D.'s answer will not work.
2 Comments
ray
ormap is not available before r6rs.Eli Barzilay
(1) I started it with an "if"; (2) R6RS is Scheme; (3) even in pre-R6RS schemes such a function is very common -- for example, SRFI-1's
any.(define (has-list? X) (apply or (map list? X)))
1 Comment
Dan D.
this doesn't work if
or is a macro (as it is in racket (plt-scheme))