简单的LISP问题

时间:2011-05-06 17:36:30

标签: lisp common-lisp

我只是在学习LISP而我在执行以下操作时遇到了麻烦:

; 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))

我知道我很接近,但我只是遗漏了一些东西。

非常感谢: - )

1 个答案:

答案 0 :(得分:5)

更改get-char功能,以便从字符中返回关键字列表:

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

评估(get-char) =&gt; (:A :B)。此外:

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

=&GT;

("1" "2")