tags:

views:

175

answers:

2

How would I go about adding values from a tab delimited string to a plist?

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

*lines* is a list of tab delimited strings loaded from a file, and I want to make a plist of the form

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

Thanks!

+5  A: 
(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")
Rainer Joswig
thanks that's a really good answer I can't vote them up yet though but I will when I can thanks :)
dunkyp
MAPCAN is my first thought, too. A little formatting hint: Currently, code highlighting doesn't work here for Lisp code, so I would just use <pre> tags.
Svante
If MAPCAN is your first thought, then you are good at Common Lisp. ;-) I was thinking, that with the site one day (!?!) might add Lisp formatting and then the code would benefit from that - not sure about <pre> formatted code then...
Rainer Joswig
I wouldn't say that I'm good, I just don't like to loop when I can map. :) I had given up on Lisp highlighting after every request for it on uservoice was closed "we use prettify.js", even though prettify.js does have a module for lisp. There seems to be hope recently, though.
Svante
+2  A: 

You should read the lines from the file, CL-PPCRE:SPLIT them to get the list, and step through this list:

(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))
dmitry_vk