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