I am currently writing a LISP program which analyses the CR results in the form of lists like following:
(“I” 0 10 0 20) << (word X0 X1 Y0 Y1)
It must build the whole text using positions of words.
My code has a cluster analyser which finds out cluster layouts like paragraphs with left- alignment or right or even both. A cluster data structure seems like this:
(“cluster name” xline y0 y1 ‘(cluster words))
How can i add a new line while i am iterating over a list of strings and concatenate them into result string to create a formatted text from these?
Example:
"Hi,\n
\n
here is my entry\n
\n
Good bye"
My code seems like following:
(defun print-formatted-text(txt)
(let
((size (array-total-size txt))
(sorted (sort (sort txt #'compare-mix) #'compare-generic2))
(result ""))
(loop for i from 0 to (1- size) do
(let ((el (aref sorted i)))
(if (word? el)
(setf result (concatenate 'string result (first el) " "))
(if (null (nth 7 el))
nil
(progn
(setf result (concatenate 'string result " "))
(dolist (curr (nth 7 el))
(setf result (concatenate 'string result (first curr) " "))))))))
result))
If the current data isn’t a word, then it is a paragraph. It means, i need to add a new line before i give the words of paragraph out and after.
Is the usage of concatenate properly here?
Thank you for your advices.
I can’t quite follow your program, but it’s much easier to work with string-streams and use
format,write-string,write-line,terpri, and related functions, e.g.