Here's a brief problem:
Input: a list of strings, each of which contains numbers
("3.4 5.4 1.2 6.4" "7.8 5.6 4.3" "1.2 3.2 5.4")
Exit: list of numbers
(3.4 5.4 1.2 6.4 7.8 5.6 4.3 3.2 5.4)
Here is my coding attempt:
(defun parse-string-to-float (line &optional (start 0)) "Parses a list of floats out of a given string" (if (equalp "" line) nil (let ((num (multiple-value-list (read-from-string (subseq line start))))) (if (null (first num)) nil (cons (first num) (parse-string-to-float (subseq line (+ start (second num))))))))) (defvar *data* (list " 3.4 5.4 1.2 6.4" "7.8 5.6 4.3" "1.2 3.2 5.4")) (setf *data* (format nil "~{~a ~}" *data*)) (print (parse-string-to-float *data*)) ===> (3.4 5.4 1.2 6.4 7.8 5.6 4.3 1.2 3.2 5.4)
However, for fairly large datasets, this is a slow process. I assume that recursion is not as dense as possible, and I'm doing something unnecessary. Any ideas?
In addition, the grandiose project includes an input file with various sections of data separated by keywords. Example -
%FLAG START_COORDS 1 2 5 8 10 12 %FLAG END_COORDS 3 7 3 23 9 26 %FLAG NAMES ct re ct cg kl ct
etc ... I am trying to parse a hash table with keywords that follow% FLAG as keys, and the values ββare stored as numeric or string lists depending on the particular keyword that I am processing. Any ideas for libraries that are already doing this work, or simple ways to get around this in lisp?
source share