It looks like you're trying to create a list called newlist
which contains all those elements of elements
that are numbers. If so, you can just use the filter
function like this:
(let
[elements whatever
newlist (filter number? elements)]
do-stuff-with-newlist)
filter
takes a predicate function and a list and returns a new list that contains those items for which the predicate returns a true result.
Note that your initial idea of adding to a list inside a for-loop would not work because lists are immutable, so you can not add to them in-place. You could re-assign a variable holding the list inside a for loop (something like (set! my-list (cons e my-list))
, but that would not be idiomatic Clojure code. It would also create the list in reverse.