1

I get this error:

IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Symbol clojure.lang.RT.seqFrom (RT.java:542)

when I call this function:

    (defn my-butlast [lista]
      (loop [c lista
             last ()]
        (if (= (count c) 1)
          last
          (recur (concat last (first c))
                 (pop c)))))

The function should return a list with the same elements as its input list but excluding the last element, or '()' if it's empty.

And the error only happens when the list has two or more elements like this:

(my-butlast '(a b))

3 Answers 3

2

concat: "concatenation of the elements in the supplied colls" (taken from https://clojuredocs.org/clojure.core/concat). Your error seems to be consistent with not passing concat the correct argument types. You could try using conj in place of concat, or else wrapping the second argument to concat in a vector.

If you choose conj be sure to understand the different behavior between conj-ing onto a list verses onto a vector: https://clojuredocs.org/clojure.core/conj

Sign up to request clarification or add additional context in comments.

Comments

1

I would suggest a diferent approach, a bit simpler in my opinion. Try something like (reverse (rest (reverse list))).

If that's all you need, no need to complicate. If you actually have a reason why you started like that, just read a bit about concat, that's where the error is coming from.

Comments

1

As others have said, concat only takes collections.

Here is the offending expression: (concat last (first c))

Have a look at these links as they provide some useful techniques in order to help debug your Clojure code:

REPL DEBUGGING: NO STACKTRACE REQUIRED

Debugging with the Scientific Method - Stuart Halloway

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.