eg/twisted: Modified to follow the newer hy syntax
Updated example to follow newer function syntax, also replaced `caddr' by `second'.
This commit is contained in:
parent
baa9f7436e
commit
b8efb5c242
@ -14,32 +14,26 @@
|
|||||||
[twisted.internet [reactor]]
|
[twisted.internet [reactor]]
|
||||||
[twisted.python [log]])
|
[twisted.python [log]])
|
||||||
|
|
||||||
(defun get-page-size (result)
|
(defn get-page-size [result]
|
||||||
(print
|
(print
|
||||||
(+ "Byte count for the content of the HTTP page passed: "
|
(+ "Byte count for the content of the HTTP page passed: "
|
||||||
(str (len result)))))
|
(str (len result)))))
|
||||||
|
|
||||||
(defun log-error (err)
|
(defn log-error [err]
|
||||||
(log.msg err))
|
(log.msg err))
|
||||||
|
|
||||||
(defun finish (ignore)
|
(defn finish [ignore]
|
||||||
(log.msg "Preparing to stop reactor ...")
|
(log.msg "Preparing to stop reactor ...")
|
||||||
(reactor.stop))
|
(reactor.stop))
|
||||||
|
|
||||||
(defun get-page (url)
|
(defn get-page [url]
|
||||||
(let ((d (getPage url)))
|
(let [[d (getPage url)]]
|
||||||
(d.addCallback get-page-size)
|
(d.addCallback get-page-size)
|
||||||
(d.addErrback log-error)
|
(d.addErrback log-error)
|
||||||
(d.addCallback finish)))
|
(d.addCallback finish)))
|
||||||
|
|
||||||
(defun caddr (list)
|
|
||||||
; This is how you'd do this in CL:
|
|
||||||
;(car (cdr (cdr list))))
|
|
||||||
; However, I think this is more efficient in hy:
|
|
||||||
(get list 2))
|
|
||||||
|
|
||||||
(if (= __name__ "__main__")
|
(if (= __name__ "__main__")
|
||||||
(do
|
(do
|
||||||
(log.startLogging sys.stdout)
|
(log.startLogging sys.stdout)
|
||||||
(get-page (caddr sys.argv))
|
(get-page (second sys.argv))
|
||||||
(reactor.run)))
|
(reactor.run)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user