In a recent project, I needed to test if two lists of strings were equal. That is, if both lists contained the same strings in the same order.
Perhaps this will be useful for others, so I’ll post the function here:
;;; Return true if lists of strings are equal, else NIL (defun strlist= (lista listb) (and (= (length lista)(length listb)) (block test (mapc (lambda (x y) ;(format t "~s = ~s~%" x y) (unless (string= x y) (return-from test nil))) lista listb) t)))
(setf first-string (list "Hello" "World")) (setf second-string (list "Hello" "World")) (setf third-string (list "hello" "world")) (setf fourth-string (list "Hello" "World" "again")) (strlist= first-string second-string) ;returns T (strlist= first-string third-string) ;returns NIL (case sensitive comparison) (strlist= first-string fourth-string) ;returns NIL (different length lists)