That's a mouthfull.
My brain is just not working today. Normally I write, vb style, and then work backwards, because that's how lisp is to me... backwards. hehe.
But today, I just can't see the "hook". I run it through in my mind, and each chess move fails before I can even begin typing.
Sample data will average a couple hundred entries, no more than a few thousand.
(setq a '(((2 3) "2-3")
((1 0) "1-0")
((2 0) "2-0")
((1 3) "1-3")
((2 2) "2-2")
((2 3) "2-3")
((1 2) "1-2")
((0 0) "0-0")
((0 1) "0-1")
((1 1) "1-1")
((0 2) "0-2")
((2 1) "2-1")
)
(merge-grids a)
;_1_$(((2 1) "2-1") ((0 2) "0-2") ((2 0) "2-0") ((1 0) "1-0\n1-0") ((2 3) "2-3\n2-3"))
The text/string value is irrelevant, and may include much more data in the future (eg. enames, tmatrix, vla ref's). However the text value will always be last
The code's intent is to find duplicate coordinates and merge what text it finds with a new line. Duplicate coords will be rare (1 in 50~100).
(defun merge-grids (indexed_lst
/
return item duplicates
)
(while indexed_lst
(setq item (car indexed_lst)
indexed_lst (cdr indexed_lst))
(if (setq duplicates (vl-remove-if-not (function (lambda (x) (equal (car x) (car item)))) indexed_lst))
(progn
(setq indexed_lst (vl-remove-if (function (lambda (x) (equal (car x) (car item)))) indexed_lst))
(setq item (list (car item) (vl:list->string "\n" (cons (last item) (mapcar 'last duplicates)))))
);progn
);if dudplicates
(setq return (cons item return))
);while list
);defun merge-grids
(defun vl:list->string (delim ls / out)
(setq out (apply 'strcat (mapcar (function (lambda (x) (strcat x delim))) ls)))
(if out (vl-string-right-trim delim out))
);defun list->string