In racket, Use a function cons to build a list from elements ‘2, ‘t and ‘x in this particular order.
ANS:-
You want to return two lists one for element that passed,and one for the elements that failed.
so,here is its code:-
(define tear
(lambda (pred xs)
(cond
[(null? xs)
(values '() '())]
[(pred (car xs))
(let-values ([(A B) (tear pred (cdr xs))])
(values (cons (car xs) A)
B))]
[else
(let-values ([(A B) (tear pred (cdr xs))])
(values A
(cons (car xs) B)))])))
(tear number? '(1 2 3 a b c))
;=> (1 2 3)
; (a b c)
(tear list? (list '(1 2 3) "not a list" '(4 5)))
;=> ((1 2 3) (4 5))
; ("not a list")
Get Answers For Free
Most questions answered within 1 hours.