elisp - Lisp match keywords and find values -


say have list keywords:

'(("element1" :keyword1 "a" :keyword2 "b")    ("element2" :keyword3 "c" :keyword4 "d")   ("element3" :keyword2 "e" :keyword4 "f")) 

which functions can use find list elements contain :keyword2 , find value in each list? i'm trying in emacs lisp think cl package possibly adapt common lisp solution? i've tried use find function illustrated here no avail (of course, after changing few syntax elements adapt examples emacs lisp).

 (require 'cl)  (defvar *data* '(("element1" :keyword1 "a" :keyword2 "b")                   ("element2" :keyword3 "c" :keyword4 "d")                  ("element3" :keyword2 "e" :keyword4 "f")))  (find :keyword2 *data* :test #'find) ;;=> ("element1" :keyword1 "a" :keyword2 "b")  (getf (cdr (find :keyword2 *data* :test #'find)) :keyword2) ;;=> "b"  ;; above finds first match; find matches,  ;; use remove* remove elements not contain keyword:  (remove* :keyword2 *data* :test-not #'find) ;;=> (("element1" :keyword1 "a" :keyword2 "b") ;;    ("element3" :keyword2 "e" :keyword4 "f"))  (mapcar (lambda (x) (getf (cdr x) :keyword2))         (remove* :keyword2 *data* :test-not #'find)) ;;=> ("b" "e")  

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -