schmoopy
schmoopy

Reputation: 6649

Simple LISP question

I'm just learning LISP and i am having trouble doing the following:

; return ":h :i"
(defun get-char() 
  (loop for char across "ab" 
        collect (concatenate 'string ":" (string char))))

; plist
(defun get-list() (list :a "1" :b "2"))

; I cannot get this to work 
; <-- returns all null, cannot get plist values :-(
(loop for x in (get-char) 
      collect (getf (get-list) x))

; this works fine...
(loop for x in '(:a :b) 
      collect (getf (get-list) x))

I know im close, but i am just missing something.

Thanks a lot :-)

Upvotes: 1

Views: 477

Answers (1)

Terje Norderhaug
Terje Norderhaug

Reputation: 3689

Change the get-char function to return a list of keywords from the characters:

(defun get-char() 
  (loop 
    for char across "ab" 
    collect (intern (string-upcase char) :keyword)))

Evaluating (get-char) => (:A :B). Furthermore:

(loop for x in (get-char) collect (getf (get-list) x))

=>

("1" "2")

Upvotes: 5

Related Questions