9f88e07e1d
This changes let to use a flat list of symbol-value pairs instead of a vector of vectors. One side effect is that (let [[a 1] z]) is not expressible now, and one will explicitly need to set a nil value for z, such as: (let [a 1 z nil]). Closes #713. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
40 lines
1.3 KiB
Hy
40 lines
1.3 KiB
Hy
;; To run this example, do the following:
|
|
;; $ hy get-page.hy http://docs.hylang.org/en/latest/
|
|
;;
|
|
;; At which point, you should see output like this:
|
|
;; 2013-06-24 23:03:57-0700 [-] Log opened.
|
|
;; 2013-06-24 23:03:57-0700 [-] Starting factory <HTTPClientFactory: http://docs.hylang.org/en/latest/>
|
|
;; 2013-06-24 23:03:57-0700 [HTTPPageGetter,client] Byte count for the content of the HTTP page passed: 11835
|
|
;; 2013-06-24 23:03:57-0700 [HTTPPageGetter,client] Preparing to stop reactor ...
|
|
;; 2013-06-24 23:03:57-0700 [HTTPPageGetter,client] Stopping factory <HTTPClientFactory: http://docs.hylang.org/en/latest/>
|
|
;; 2013-06-24 23:03:57-0700 [-] Main loop terminated.
|
|
(import sys)
|
|
|
|
(import [twisted.web.client [getPage]]
|
|
[twisted.internet [reactor]]
|
|
[twisted.python [log]])
|
|
|
|
(defn get-page-size [result]
|
|
(print
|
|
(+ "Byte count for the content of the HTTP page passed: "
|
|
(str (len result)))))
|
|
|
|
(defn log-error [err]
|
|
(log.msg err))
|
|
|
|
(defn finish [ignore]
|
|
(log.msg "Preparing to stop reactor ...")
|
|
(reactor.stop))
|
|
|
|
(defn get-page [url]
|
|
(let [d (getPage url)]
|
|
(d.addCallback get-page-size)
|
|
(d.addErrback log-error)
|
|
(d.addCallback finish)))
|
|
|
|
(if (= __name__ "__main__")
|
|
(do
|
|
(log.startLogging sys.stdout)
|
|
(get-page (second sys.argv))
|
|
(reactor.run)))
|