dunkyp
dunkyp

Reputation: 178

Adding values from a tab delimited string to a plist

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!

Upvotes: 2

Views: 590

Answers (2)

dmitry_vk
dmitry_vk

Reputation: 4469

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

Upvotes: 2

Rainer Joswig
Rainer Joswig

Reputation: 139381

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

Upvotes: 5

Related Questions