Puzzling list comp error: "Don't know how to create ISeq from: clojure.lang.Keyword"

987 views
Skip to first unread message

gvim

unread,
Aug 30, 2014, 9:47:20 AM8/30/14
to clo...@googlegroups.com
I have a long function which produces `list-of-lists` :

(("Sun" "21" "li" "13" "201.2139410")
("Moon" "11" "le" "21" "131.3457459")
......)

.... before entering a list comprehension (simplified for brevity):

(defn calc .......
(let [ .....
.......
list-of-lists (map #(rest (first %)) results)]
(for [l list-of-lists
plan (keyword (first l))
deg (Integer/parseInt (second l))
sign (signs (keyword (first (rest (rest l)))))
min (Integer/parseInt (second (rest (rest l))))
long (Float/parseFloat (last l))]
{:deg deg :min min :long long})))

When I call the function I get this error:

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

I've tested all the bindings in the repl and they produce the desired
data so it seems the final construction of the map is where the problem
lies.

gvim


Alexey Kachayev

unread,
Aug 30, 2014, 10:07:16 AM8/30/14
to clo...@googlegroups.com
for macro expects each pair to be either binding-form/collection-expr or one of known modifiers (:let, :when, :while).

Here:

plan (keyword (first l))

you give a pair of binding-form and keyword (which is really impossible to iterate over). 

If you meant let-binding for plan, dec, min and long, use :let modifier (you can find example in documentation - http://clojuredocs.org/clojure_core/clojure.core/for).




gvim


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Kind regards,
Alexey S. Kachayev, 
CTO at Attendify.com
----------
Skype: kachayev
Tel: +380-996692092

gvim

unread,
Aug 30, 2014, 11:21:05 AM8/30/14
to clo...@googlegroups.com
On 30/08/2014 15:07, Alexey Kachayev wrote:
> for macro expects each pair to be either binding-form/collection-expr or
> one of known modifiers (:let, :when, :while).
>
> Here:
>
> plan (keyword (first l))
>
> you give a pair of binding-form and keyword (which is really impossible
> to iterate over).
>
> If you meant let-binding for plan, dec, min and long, use :let modifier
> (you can find example in documentation -
> http://clojuredocs.org/clojure_core/clojure.core/for).
>

Yes, of course :) I confused list comp bindings with let bindings. Thanks.

gvim

gvim

unread,
Aug 30, 2014, 11:49:02 AM8/30/14
to clo...@googlegroups.com
On 30/08/2014 15:07, Alexey Kachayev wrote:
> for macro expects each pair to be either binding-form/collection-expr or
> one of known modifiers (:let, :when, :while).
>
> Here:
>
> plan (keyword (first l))
>
> you give a pair of binding-form and keyword (which is really impossible
> to iterate over).
>
> If you meant let-binding for plan, dec, min and long, use :let modifier
> (you can find example in documentation -
> http://clojuredocs.org/clojure_core/clojure.core/for).
>

I'm going to have to reduce the resulting list next so I thought to use
a map version of the list comp. but ran into a similar error:

(defn calc .......
(let [ .....
.......
list-of-lists (map #(rest (first %)) results)]
(-> list-of-lists
(map #(let [plan (keyword (first %))
deg (Integer/parseInt (second %))
sign (signs (keyword (first (rest (rest %)))))
min (Integer/parseInt (second (rest (rest %))))
long (Float/parseFloat (last %))]
{plan {:sign sign :deg deg :min min :long long}})))


"Don't know how to create ISeq from: astro.calc$calc$fn__29869"

Now I'm using a let form but the error is similar.

gvim
















>
> 2014-08-30 16:47 GMT+03:00 gvim <gvi...@gmail.com
> <mailto:gvi...@gmail.com>>:
>
> I have a long function which produces `list-of-lists` :
>
> (("Sun" "21" "li" "13" "201.2139410 <tel:201.2139410>")
> <mailto:clo...@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+unsubscribe@__googlegroups.com
> <mailto:clojure%2Bunsu...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/__group/clojure?hl=en
> <http://groups.google.com/group/clojure?hl=en>
> --- You received this message because you are subscribed to the
> Google Groups "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to clojure+unsubscribe@__googlegroups.com
> <mailto:clojure%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/__optout
> <https://groups.google.com/d/optout>.
>
>
>
>
> --
> Kind regards,
> Alexey S. Kachayev,
> CTO at Attendify.com
> ----------
> http://github.com/kachayev
> http://twitter.com/kachayev
> Skype: kachayev
> Tel: +380-996692092
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to clojure+u...@googlegroups.com
> <mailto:clojure+u...@googlegroups.com>.

Alexey Kachayev

unread,
Aug 30, 2014, 12:05:04 PM8/30/14
to clo...@googlegroups.com
Thread-first macro -> will insert list-of-lists as first argument for map, which is definitely not what you expect. Use threading-last ->> instead.


    <mailto: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+unsubscribe@__googlegroups.com

    For more options, visit this group at
    http://groups.google.com/__group/clojure?hl=en

    <http://groups.google.com/group/clojure?hl=en>
    --- You received this message because you are subscribed to the
    Google Groups "Clojure" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to clojure+unsubscribe@__googlegroups.com

    For more options, visit https://groups.google.com/d/__optout
    <https://groups.google.com/d/optout>.





--
Kind regards,
Alexey S. Kachayev,
CTO at Attendify.com
----------
http://github.com/kachayev
http://twitter.com/kachayev
Skype: kachayev
Tel: +380-996692092

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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

For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send

For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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

For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

gvim

unread,
Aug 30, 2014, 12:19:31 PM8/30/14
to clo...@googlegroups.com
On 30/08/2014 17:04, Alexey Kachayev wrote:
> Thread-first macro ->will insert list-of-listsas first argument for map,
> which is definitely not what you expect. Use threading-last ->>instead.
>

I've never quite understood the distinction other than -> does
everything top to bottom and ->> does the reverse. From what you're
saying the choice also affects which position the argument is inserted?
If so this presents a complication in that threading through several
functions may require the argument to be inserted in different positions?

gvim

Sam Raker

unread,
Aug 30, 2014, 1:05:06 PM8/30/14
to clo...@googlegroups.com
`->` inserts its first argument into the second position of the next argument, and so on, so
(-> []
 
(conj 1)
 
(conj 2))

Turns into
(conj (conj [] 1) 2)

`->>` inserts its first argument into the LAST position of the next argument, and so on, so
(->> 1
 
(conj [2])
 (conj [3]))
 

Turns into
(conj [3] (conj [2] 1))

I guess it is "bottom to top," in a way, but I always thought that was kind of an artifact of the argument (re-)ordering.
Reply all
Reply to author
Forward
0 new messages