I am trying to build filter (a built-in function) using Racket just as a matter of practice.
I created the following code:
(define (filter lista-1 check-function)
(define (fil-iter lista-1 check-function lista-2)
(cond ((null? lista-1) lista-2)
((check-function (car lista-1)) (fil-iter (cdr lista-1) check-function (append lista-2 (list (car lista-1)))))
(else (fil-iter (cdr lista-1) check-function lista-2))))
(trace fil-iter)
(fil-iter lista-1 check-function '()))
I made a few tests with "odd?", "even?" and "number?" as the "check-function".
All of the outputs were correct. But I might be not seeing something... My intuition says that there is something wrong here.