2011-05-06 53 views
1

我只是學習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)) 

我知道IM接近,但我只是失去了一些東西。

非常感謝:-)

+1

提示:可能要拿出一個更具描述性的標題不是 「簡單的LISP問題」 下一次。 :-) – Ken 2011-05-08 00:22:23

回答

5

更改get-char函數從字符返回關鍵字的列表:

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

評估(get-char) =>(:A :B)。此外:

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

=>

("1" "2") 
+0

這正是我想要的 - 對我來說似乎有點神祕,但我只是開始LISP - 它是有道理的: - - - 謝謝! – schmoopy 2011-05-06 19:15:27