GregGleason Posted December 3, 2017 Posted December 3, 2017 I have a routine that reads two files and reports if there are differences. The data is place in "out1" for file 1 and "out2" for file 2. As a test, I have it read the same file. It says that they are not equal. When I do this it reports a "YES!!" (if (= out1 out1) (princ "\nYES!!") (princ "\nno.") ) When I do this it reports a "no." (if (= out1 out2) (princ "\nYES!!") (princ "\nno.") ) Any thoughts as to what is going on? Below is the complete routine: (defun c:ctf (/ fil fl i mycount out1 out2 rec) ;; String to List - Lee Mac ;; Separates a string using a given delimiter ;; str - [str] String to process ;; del - [str] Delimiter by which to separate the string ;; Returns: [lst] List of strings (defun lm:str->lst (str del / pos) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (lm:str->lst (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) ; End of lm:str->lst ; =========================================================================================================== ; Read File 1 (setq fl nil) (setq fil nil) (if (setq fl (open "C:\\Users\\ggleason\\Documents\\CADWorx\\CADWorx.Projects\\Exxon.Joliet.2015-151\\IsoLayers\\ExxonMobil.Iso.Border.Acad.v.2007.dwg.txt" "r")) (progn (setq mycount 0) (while (setq fil (read-line fl)) (setq mycount (1+ mycount)) ; SYNTAX: (princ "\nMy Name is \nJohn")(princ) ; (princ mycount)(princ "\n") (setq out1 (cons (lm:str->lst fil "\t") out1)) ) ; End of "While" loop (close fl) (princ (strcat (itoa mycount) " records read in File 1\n")) ) ) ; End of "If" statement for File 1 ;; Reverse results to put them in correct order (setq out1 (reverse out1)) ; End of File 1 ; =========================================================================================================== ; Read File 2 (setq fl nil) (setq fil nil) (if (setq fl (open "C:\\Users\\ggleason\\Documents\\CADWorx\\CADWorx.Projects\\Exxon.Joliet.2015-151\\IsoLayers\\ExxonMobil.Iso.Border.Acad.v.2007.dwg.txt" "r")) (progn (setq mycount 0) (while (setq fil (read-line fl)) (setq mycount (1+ mycount)) ; SYNTAX: (princ "\nMy Name is \nJohn")(princ) ; (princ mycount)(princ "\n") (setq out2 (cons (lm:str->lst fil "\t") out2)) ) ; End of "While" loop (close fl) (princ (strcat (itoa mycount) " records read in File 2\n")) ) ) ; End of "If" statement for File 2 ;; Reverse results to put them in correct order (setq out2 (reverse out2)) ; End of File 2 ; =========================================================================================================== ; SYNTAX: (if (= 1 3) "YES!!" "no.") (if (= out1 out2) (princ "\nYES!!") (princ "\nno.") ) (princ "\n ------------------------------------------------") (princ "\n") (princ out1) (princ "\n ------------------------------------------------") (princ "\n") (princ out2) (princ "\n ------------------------------------------------") (princ) ) ; End of c:ctf Greg Quote
BIGAL Posted December 3, 2017 Posted December 3, 2017 Is there some reason why you are not comparing each line as read from the two files ? I did code on a test file and it came back No. Quote
Lee Mac Posted December 3, 2017 Posted December 3, 2017 Per the documentation, the '=' function should be used for numerical or string comparison, not for list comparison - observe: _$ (= '(1 2 3) '(1 2 3)) nil Instead, you should use the equal function. _$ (equal '("a" "b" "c") '("a" "b" "c")) T Quote
Grrr Posted December 3, 2017 Posted December 3, 2017 Aside of Lee's most obvious suggestion (using the equal function), heres an alternative if one deals only with list of strings: (vl-every '= '("a" "b" "c") '("a" "b" "c") '("a" "b" "c")) hence: (vl-every '= ListOfStrings1 ListOfStrings2 ListOfStrings3 ...) and even: (apply 'vl-every (cons '= ListOfStringLists)) Although I'd use equal myself, since it works with nested lists. Quote
GregGleason Posted December 4, 2017 Author Posted December 4, 2017 Is there some reason why you are not comparing each line as read from the two files ? I did code on a test file and it came back No. I would have like to have done that, but I was not sure how to go about it. Greg Quote
GregGleason Posted December 4, 2017 Author Posted December 4, 2017 Per the documentation, the '=' function should be used for numerical or string comparison, not for list comparison - observe: _$ (= '(1 2 3) '(1 2 3)) nil Instead, you should use the equal function. _$ (equal '("a" "b" "c") '("a" "b" "c")) T Thank you for clearing that up. Also, I appreciate all of the great information you put out there for us to learn from. Greg Quote
GregGleason Posted December 4, 2017 Author Posted December 4, 2017 Aside of Lee's most obvious suggestion (using the equal function), heres an alternative if one deals only with list of strings: (vl-every '= '("a" "b" "c") '("a" "b" "c") '("a" "b" "c")) hence: (vl-every '= ListOfStrings1 ListOfStrings2 ListOfStrings3 ...) and even: (apply 'vl-every (cons '= ListOfStringLists)) Although I'd use equal myself, since it works with nested lists. That is great information. Thank you. Greg Quote
Stefan BMR Posted December 4, 2017 Posted December 4, 2017 Aside of Lee's most obvious suggestion (using the equal function), heres an alternative if one deals only with list of strings: (vl-every '= '("a" "b" "c") '("a" "b" "c") '("a" "b" "c")) There is a major difference between vl-every '= and equal _$ (equal '("a" "b") '("a" "b" "c")) -> nil _$ (vl-every '= '("a" "b") '("a" "b" "c")) -> T Quote
Grrr Posted December 4, 2017 Posted December 4, 2017 There is a major difference between vl-every '= and equal _$ (equal '("a" "b") '("a" "b" "c")) -> nil _$ (vl-every '= '("a" "b") '("a" "b" "c")) -> T Thanks for pointing this out, Stefan! I've forgot that vl-every processes like mapcar. So that suggestion should be used in conjunction with equal length check of the lists. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.