I know this is a bit elementary, but I am highly uncomfortable writing Scheme code, and I want to make sure that what I'm doing is good practice. I know mutation is frowned upon in Scheme.
I have no other source of review so I have come to you all.
(define (filter-lst fn lst)
(if (not (null? lst))
(if (fn (car lst))
(cons (car lst) (filter-lst fn (cdr lst)))
(filter-lst fn (cdr lst))
)
'()
)
)
Note: The function seems to be working according to a few test cases I ran.
As a follow-up PURELY STYLISTIC question, which of these is preferred?
#1
(define (merge l1 l2)
(if (null? l1) l2
(if (null? l2) l1
(cons (car l1) (cons (car l2) (merge (cdr l1) (cdr l2)))))))
#2
(define (merge l1 l2)
(if (null? l1) l2
(if (null? l2) l1
(cons (car l1) (cons (car l2) (interleave (cdr l1) (cdr l2))))
)
)
)