0
votes

I've just started learning Clojure and I'm attempting to write something to pull some URL's from a web page into memory with some additional meta data around each URL.

I can get the URLs but it's storing them somewhere that I'm having an issue with. I've figured out I need a vector with nested maps, which I can then add new records to with assoc-in, however since I don't know the URL's I'm not sure how I go about defining my data structure initially.

So for example:

(def *comics*
  [{:name "Penny-Arcade"
    :url "http://www.penny-arcade.com/comic/"
    :working 0
   }
   {:name "We The Robots"
    :url "http://www.wetherobots.com/"
    :working 0
   }])

I'm just not sure how I start the above data structure with no data in it, then add it say initially from a command line arg, then the rest from the website.

If someone can suggest a better way that the above to store the data, please feel free.

1

1 Answers

2
votes

I take it you want to modify your *comics* var from some command line argument - and then modify it even more while "working" on the elements in it.

I would suggest you don't do that.

There doesn't seem to be any reason you can't take the comics urls from the command line and pass them as arguments to a function that does the processing and returns whatever you want from those urls. Doing it that way - that is; functionally, without mutating vars - will definitely be easier to implement in clojure, easier to parallellize and just all out more idiomatic and fun.