0
votes

I am wondering how to combine two or more different sequences with different types of elements into one list. Like:

(defn combine [vector]
   (conj '(remove number? vector) 10))

Here is a test:

(combine [1 2 d g f e ])

This is the error:

CompilerException java.lang.RuntimeException: Unable to resolve symbol: d in this context,

I want to know can use "conj, concat, into" these functions to combine them. Also, I have add quote in front of the list (d g f e), but the error says d cannot be solved. Is anyone help me to figure out this problem? Thank you so much!

2
Your test doesn't "combine two or more different sequences". Please describe your input and desired output more clearly. - jmargolisvt
A more usual (than quoting) way when just testing is to use keywords, so you would have :d :g :f :e, and avoid troubles altogether. - Chris Murphy

2 Answers

3
votes

quote the input to the function to prevent it from resolving the symbols in the list:

(combine '[1 2 d g f e ])

the ' is a shortcur (reader macro) for the quote function. otherwise it will attempt to trnslate (called "evaluation" in Clojure-speak) the symbols in the vector before it passes the vector to the combine function. with the ' it will try to look up a var in the current namespace names d and get it's value in order to put it into the vector.

1
votes

The quote is in the wrong place. Try

(defn combine [vector]
   (conj (remove number? vector) 10))

(combine '(1 2 d g f e)) 
;(10 d g f e)