Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print keys from plist based on values?

How do i iterate and print the keys of a plist based on given values?

Example:

; 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

Im new to lisp - thank you :-)

like image 861
schmoopy Avatar asked May 09 '11 19:05

schmoopy


Video Answer


1 Answers

Something like

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

The first line moves a pattern over the list.

like image 132
Rainer Joswig Avatar answered Sep 17 '22 12:09

Rainer Joswig