将制表符分隔的字符串中的值添加到plist

时间:2009-03-28 02:14:57

标签: common-lisp

如何将制表符分隔的字符串中的值添加到plist?

  (dolist (x *lines*)
    (cl-ppcre:split "\t" x))

*lines*是从文件加载的制表符分隔字符串列表,我想制作表单的plist

(:a value1 :b value2 :c value 3)

谢谢!

2 个答案:

答案 0 :(得分:5)

(let ((line '("foo" "bar" "baz")))
   (loop for item in line and key in '(:a :b :c) collect key collect item))


=> (:A "foo" :B "bar" :C "baz")


(mapcan 'list '(:a :b :c) '("foo" "bar" "baz"))

=> (:A "foo" :B "bar" :C "baz")

答案 1 :(得分:2)

你应该读取文件中的行,CL-PPCRE:SPLIT它们来获取列表,并逐步浏览这个列表:

(loop
   for (key value) on (cl-ppcre:split " " "a value1 b value2 c value3") by #'cddr
   appending (list (intern (string-upcase key) (find-package :keyword))
                   value))