亚历山大一直很擅长将简单的alist转换为plist,例如:
> (get-document "flower-photo-with-lytro")
((:|_id| . "flower-photo-with-lytro")
(:|_rev| . "6-eb6d9b71251c167039d3e73d8c0c9a63")
(:TITLE . "flower-photo-with-lytro")
(:AUTHOR . "devnull")
(:TEXT . "hello here is a sample flower .... ")
(:TIME . "3558566236"))
> (alexandria:alist-plist (get-document "flower-photo-with-lytro"))
(:|_id| "flower-photo-with-lytro" :|_rev| "6-eb6d9b71251c167039d3e73d8c0c9a63"
:TITLE "flower-photo-with-lytro" :AUTHOR "devnull"
:TEXT "hello here is a sample flower .... " :TIME "3558566236")
如何使用alexandria格式化更具结构性的列表,如
> (invoke-view "hulk" "time")
((:|total_rows| . 2)
(:|offset| . 0)
(:|rows|
((:|id| . "flower-photo-with-lytro")
(:|key| . "3558566236")
(:|value| . "flower-photo-with-lytro"))
((:|id| . "hello-world-in-common-lisp-and-restas")
(:|key| . "3558567019")
(:|value| . "3558567019-hello-world-in-common-lisp-and-restas"))))
获取带有:id,:key和:value?
的plist答案 0 :(得分:2)
(defparameter *test*
'((:|total_rows| . 2)
(:|offset| . 0)
(:|rows|
((:|id| . "flower-photo-with-lytro")
(:|key| . "3558566236")
(:|value| . "flower-photo-with-lytro"))
((:|id| . "hello-world-in-common-lisp-and-restas")
(:|key| . "3558567019")
(:|value| . "3558567019-hello-world-in-common-lisp-and-restas")))))
(defun rows-alist (tree)
(list (car tree)
(cadr tree)
(alexandria:flatten (caddr tree))))
好吧,我会猜测......
如果您想重命名关键字:
(defun rows-alist (tree)
(list (car tree)
(cadr tree)
(mapcar
#'(lambda (x)
(if (symbolp x)
(intern
(string-upcase (symbol-name x))
"KEYWORD") x))
(alexandria:flatten (caddr tree)))))