Clojure beginner here, not sure if the terminology in the question is even correct.
I'm building a web scraper using the clj-webdriver taxi api. There are several sites that it needs to scrape data from. The following isn't actually code from the project, but I've tested it and verified that it illustrates my question:
(def gh-un "my-username")
(def gh-pw "my-password")
;; print the first five "starred" alerts from my github feed
(defn get-info [url]
(to url)
(click "a[href='/login']")
(input-text "input#login_field" gh-un)
(input-text "input#password" gh-pw)
(click "input.btn")
(pprint (map text (take 5 (find-elements {:css "div.alert.watch_started"}))))
(click "img.avatar")
(click "button.dropdown-signout"))
(defn github-wrapper []
(map get-info (repeat 3 "http://www.github.com"))
(quit))
If I call (github-wrapper)
as is, the browser window will close almost immediately, because of the (quit)
call. Wrapping the map
call with doall
, i.e. (doall (map get-info (repeat 3 "http://www.github.com")))
, solves this problem, which suggests that the problem is that map produces a lazy sequence that's not getting consumed, and therefore I'm not seeing the side-effects of the calls to get-info
.
However, if I remove the (quit)
call at the end of get-info
, github-wrapper
does what I want it to.
My question is, why does the lazy sequence get consumed in the latter case, but not in the former?