Re: Newbie: adding items to a global vector in doseq

2014-08-15 Thread Tassilo Horn
phi...@free.fr writes: I have read up on atoms and used swap! to set the urls2 vector atom in my code. Thanks. One problem remains though: I can't retrieve the atom vector's items *(nth urls 10)* throws the following exception java.lang.UnsupportedOperationException: nth not supported

Newbie: adding items to a global vector in doseq

2014-08-14 Thread phiroc
Hello, I am trying to add URLs contained in a text file (eg. apple.com, ibm.com...), to a global vector called url2, but to no avail, the vector remains empty. Any suggestions would be greatly appreciated. Many thanks. Philippe (def fich data.txt) (def urls2 (vec nil)) (defn

Newbie: adding items to a global vector in doseq

2014-08-14 Thread Mike Fikes
Read up on atoms. The results of your conj call are being discarded. For example, check out the behavior of this: (def urls2 (atom [])) (swap! urls2 conj http://foo.bar;) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send

Re: Newbie: adding items to a global vector in doseq

2014-08-14 Thread phiroc
Hi Mike, I have read up on atoms and used swap! to set the urls2 vector atom in my code. Thanks. One problem remains though: I can't retrieve the atom vector's items *(nth urls 10)* throws the following exception java.lang.UnsupportedOperationException: nth not supported on this type: Atom

Re: Newbie: adding items to a global vector in doseq

2014-08-14 Thread phiroc
Just solved the problem by prepending at at-sign, in both cases: ( *nth @urls 10)(doseq [x @urls] (println x))* Le jeudi 14 août 2014 18:05:25 UTC+2, phi...@free.fr a écrit : Hello, I am trying to add URLs contained in a text file (eg. apple.com, ibm.com...), to a global vector

Re: Newbie: adding items to a global vector in doseq

2014-08-14 Thread Thomas Heller
Hey, it's not how you'd usually do things in Clojure and I'd consider the use of an atom in this place as wrong. I was struggling with Clojure in the beginning too and my code looked pretty much like yours, but the faster you get into the Clojure mindset the easier it will be. This might be

Re: Newbie: adding items to a global vector in doseq

2014-08-14 Thread Mike Fikes
Thomas is absolutely right, Philippe. Things also get easier if you avoid, or defer side effects, and first focus on pure functions. So, for example at the REPL, you might first try processing a literal sequence of lines, repeatedly adjusting the processing code, tweaking the regex, until you