Skip to content

Instantly share code, notes, and snippets.

@robkuz
Last active December 23, 2015 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robkuz/6689840 to your computer and use it in GitHub Desktop.
Save robkuz/6689840 to your computer and use it in GitHub Desktop.
Run on Linux. I completely do not understand why this gives me an error
(require '[clojure.java.shell :as shell])
(require '[clojure.contrib.string :as string])
(def foo (-> (shell/sh "df" "-P")
(:out)
(string/split-lines)
(map (fn [z] z))))
foo
; IllegalArgumentException Don't know how to create ISeq from: user$fn__2690 clojure.lang.RT.seqFrom (RT.java:505)
@stask
Copy link

stask commented Sep 24, 2013

It's because of the last map call, it expects the function to be first and the sequence to be second.

-------------------------
clojure.core/map
([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls])
  Returns a lazy sequence consisting of the result of applying f to the
  set of first items of each coll, followed by applying f to the set
  of second items in each coll, until any one of the colls is
  exhausted.  Any remaining items in other colls are ignored. Function
  f should accept number-of-colls arguments.
nil

You use -> macro, which inserts the result of split-lines as second parameter of the map form:

-------------------------
clojure.core/->
([x] [x form] [x form & more])
Macro
  Threads the expr through the forms. Inserts x as the
  second item in the first form, making a list of it if it is not a
  list already. If there are more forms, inserts the first form as the
  second item in second form, etc.
nil
-------------------------

Try '->>' instead, it inserts the result as last parameter of next form.

-------------------------
clojure.core/->>
([x form] [x form & more])
Macro
  Threads the expr through the forms. Inserts x as the
  last item in the first form, making a list of it if it is not a
  list already. If there are more forms, inserts the first form as the
  last item in second form, etc.
nil
-------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment