How to filter false values ​​from a list in a racket

I am studying Racket (but probably the answer will be similar in any language of the Scheme and Scheme) and wonder how to filter the false (#f) values ​​from this list. The best I came up with is:

(filter (lambda (x) (not (eq? x #false))) '("a" "b" #f 1 #f "c" 3 #f)) '("a" "b" 1 "c" 3) ;; output 

However, I think there should be a simpler solution.

+6
source share
1 answer

You can just do

 (filter identity '("a" "b" #f 1 #f "c" 3 #f)) 

since anything not #f is considered true.

+8
source

All Articles