I have an issue that I think is related to laziness, but I am not sure
I understand where the problem lies.

Let's say I have tabular data in a sequence of sequences. I get the
second column of the table like this:

(map #(nth % 1) my-table)

I can do some sequence things directly to the list returned by the
call to function, but not everything. For example,

(distinct (map #(nth % 1) my-table))

works fine, but

(frequencies (map #(nth % 1) my-table))

throws java.lang.RuntimeException: java.lang.IndexOutOfBoundsException

My own implementation of frequencies, which is maybe a little naive,
throws the same exception. However, if I bind the result of my map
call to a variable first and then call frequencies, it works fine:

(def my-list (map #(nth % 1) my-table))
(frequencies my-list)

It is my understanding that the def does not do anything but give the
list an entry in a symbol table, but something is obviously happening.
Am I causing a lazy sequence to be populated with concrete values?


-- 
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

Reply via email to