Thanks for your suggests~
The above piece of code is just for test.
The practical problem i want to solve is that
-->read a very big log file (each line is like that : "user id, latitude,
longitude, timeStamp")
-->statistic the number of each user (store in a map like that { id1 100 ,
id2 200, id3 150 ....})
-->sorted the map by values and get the top-N user id
the main code of the former 2 steps is :
....
(let [ id-num {} ] ;;as your suggestion , here should use atom
(with-open [rdr (the file...)]
(doseq [line (line-seq rdr)]
(let [params (split each line with "," ....)
id (params 0)]
(if (id-num id)
(do inc the value ....)
(do add new k-v ....)))))
)
...
I don't want to load the total file into memory, too big.
So referencing the suggestion from internet , i am using line-seq & doseq
to deal with the big log file lazily.
Is that right way to use clojue to deal this problem?
Any suggestions will be grateful!!!
2013/10/28 Michael Klishin <[email protected]>
>
> 2013/10/28 Jiaqi Liu <[email protected]>
>
>> i really don't get it.
>> Any suggestion??
>>
>
> Clojure data structures are immutable. clojure.core/assoc
> produces a new data structure instead of changing the one you have.
>
> You can use an atom if you need to update a map from doseq
> but more likely you want to use the actual value assoc returns
> and/or clojure.core functions for manipulating collections,
> such as clojure.core/reduce.
>
> See http://clojure-doc.org/articles/language/core_overview.html,
> http://clojure-doc.org/articles/language/collections_and_sequences.html
> and
> http://clojure-doc.org/articles/language/concurrency_and_parallelism.html
> --
> MK
>
> http://github.com/michaelklishin
> http://twitter.com/michaelklishin
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
------------------------------------****
刘家齐 (Jacky Liu)
**
手机:15201091195 邮箱:[email protected]
Skype:jacky_liu_1987 QQ:406229156
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.