2011-05-09 79 views
7

如何基於給定的值迭代和打印plist的鍵?基於價值的plist打印鍵?

例子:

; plist 
(defun my-list() (list :a "hi" :b "no" :c "go")) 

; from that list i want to iterate and print out keys based on values like: 
for each x in ("hi" "go") print x 

; hoping for: 
ac 

進出口新的口齒不清 - 謝謝你:-)

回答

12

喜歡的東西

(loop for (key value) on my-list by #'cddr 
     when (member value '("hi" "go") :test #'equal) 
     do (princ key)) 

第一行移動在列表模式。

4

你可以使用循環宏:

(loop 
    for (key value . rest) on list 
    by #'cddr 
    when (find value '("foo" "bar") :test #'string=) 
    do (princ key))