I am trying to write a scheme function that takes a list of the form:
((#f ((1 1) (2 1)))
(#f ((1 3) (5 1)))
(#f ((1 4) (7 1)))
)
and removes all the #f to give a list like:
( ((1 1) (2 1))
((1 3) (5 1))
((1 4) (7 1))
)
I have tried the following code but cannot get it to work:
(define meth
(lambda lst
(if (equal? (cdr lst) '())
(cdr (car lst))
(cons (list-ref (car lst) 1) (meth (cdr lst))))))
Does anyone know how to do this? Thanks.
You can just use
mapto apply thecdrfunction to each sublist in the list, like this:(map cdr lst). However this will give youfor your sample input, which is one level of nesting more than your sample output. So to get your sample output, use
list-refto get the second element of each sublist:Edit: As Eli Barzilay helpfully pointed out, there is the
cadrfunction to get the second element of a list, so this can be shortened to: