Hi Roman! On Tue, Sep 22, 2009 at 2:58 PM, Roman Roelofsen < roman.roelof...@googlemail.com> wrote:
> > Hi there! > > Lets assume I have this map: > > user=> (def person {:name "Father" :childs [{:name "Son" :age 10}]}) > > Testing: > > user=> (-> person :childs first) > {:name "Son", :age 10} > > Now lets filter the child map: > > user=> (def only-name (fn [m] (select-keys m [:name]))) > user=> (-> person :childs first only-name) > {:name "Son"} > > So why does this not work?: > > user=> (-> person :childs first (fn [m] (select-keys m [:name]))) > java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't > know how to create ISeq from: Symbol (NO_SOURCE_FILE:59) > because -> put its firs t argument in second position into its second argument: (-> foo (fn [x] x)) becomes (fn foo [x] x) user=> (macroexpand-1 '(-> foo (fn [x] x))) (fn foo [x] x) Or this?: > > user=> (-> person :childs first #(select-keys % [:name])) > java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to > clojure.lang.IPersistentVector (NO_SOURCE_FILE:60) > Ditto. At read time, #(...) expand to seomething like (fn [x] (...)). One usual albeit somewhat ugly workaround is to put another pair of parens around the fn user=> (macroexpand-1 '(-> foo ((fn [x] x)))) ((fn [x] x) foo) HTH, Christophe --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---