I'm having trouble writing a function that returns a sublist of pairs that satisfy a condition.
Current code:
(define lst1 '((a . 8)(b . 3)(c . 1)(d . 9)(e . 4)))
(define (letter t)
(caar t))
(define (numb p)
(cdar p))
(define (satisfy? c? lst)
(cond
[(or (c? (letter lst)) (c? (numb lst))) #t]
[else #f]))
(define (find-sublist c? lst)
(cond
[(satisfy? c? lst) (cons (car lst) (find-sublist c?(cdr lst)))]
[else (find-sublist c? (cdr lst))]))
Console input:
(find-sublist (lambda(x) (> (numb x) 3)) lst1)
Wanted output:
'((a . 8)(d . 9)(e . 4))
My current input consists of contract violations of either cons or pair
car: contract violation
expected: pair?
given: '()
cdar: contract violation
expected: (cons/c pair? any/c)
given: 'a