2008/07/25

[Common Lisp] Wassar のコード片

(defun map-fringe (function tree)
(with-ca/dr tree
(cond ((endp tree)
nil)
((atom car)
(cons (funcall function car)
#1=(map-fringe function cdr)))
(t
(cons (map-fringe function car)
#1#)))))

(defun maybe-anaphora-symbol (sym)
(and (symbolp sym)
(< 1 (length (symbol-name sym)))
(char= (char (symbol-name sym) 0) #\@)
(intern (subseq (symbol-name sym) 1))))

(defmacro with-status (status &body body)
(let* (syms
(form (map-fringe (lambda (x)
(aif (maybe-anaphora-symbol x)
(progn (pushnew it syms)
it)
x))
body)))
`(json:json-bind ,syms ,status
,@form)))

(mapc {with-status _
(format t "~&~a(~a): ~a" @user_login_id @user.screen_name @text)}
(json:decode-json-from-string
(http-request "http://api.wassr.jp/statuses/friends_timeline.json"
:basic-authorization *basic-authorization*)))

0 件のコメント: