How to search plist repeatedly?

I am trying to learn LISP, and I hung on something basic -

I want to scroll through the list and find the plist value from the list value ...

; here it just looks up the plist value 
(defun get-plist-value(x) (getf (list :a "1" :b "2") x))


; this is what i want to do, but it doesnt work 
; i have tried concatenating the ":" before the x value, but it didnt work either 
(loop for x in '(a b) do (get-plist-value x))

; this works 
(get-plist-value :a)

Thank you: -)

+5
source share
2 answers

(loop for x in '(a b) do (get-plist-value x))

There are two problems here.

Firstly, the symbol adoes not match the symbol :a(if you are not in the package keyword, which is very unlikely), so it can not find anything. Similarly for b.

-, , get-plist-value, , . , collect, do; , - do (format t "~&~A" (get-plist-value x)); ..

: , :a , . - , , keyword. , . , get-plist-value , - , , , :

(defun get-plist-value (x)
  (getf (list :a "1" :b "2")
        (intern (symbol-name x) "KEYWORD")))
+7

:

(loop for x in (list :a :b)
      collect (get-plist-value x))
+4

All Articles