Reputation: 830
I'm learning Racket (but probably answer will be similar in any Scheme and scheme-derived language) and wonder how to filter out false (#f) values from a given 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 guess there has to be a simpler solution.
Upvotes: 8
Views: 1628
Reputation: 1884
You can just do
(filter identity '("a" "b" #f 1 #f "c" 3 #f))
as anything not #f is considered true.
Upvotes: 12