Happy Hobbit Posted November 24, 2015 Share Posted November 24, 2015 (edited) I'm trying to find a way of comparing the contents of a list to see if all the items are of the same value. e.g: '(2 3 2 2 2) This is obviously numeric, however it would be good if it worked on a list of text too Is there an efficient way of doing it? The only way I can think of doing it is with the following: (defun c:test ( / a b c i) (setq a '(2 2 3)) (setq b (car a)) (setq c 0) (setq i 1) (repeat (-(length a)1) (if (/= b (nth i a)) (setq c 1) ) (setq i (1+ i)) ) (if (eq c 0) (princ "\nEqual") (princ "\nNot Equal") ) (princ) ) But I bet there's a better way Edited November 24, 2015 by Happy Hobbit Quote Link to comment Share on other sites More sharing options...
rlx Posted November 24, 2015 Share Posted November 24, 2015 (edited) search for vl-every :-) http://www.cadtutor.net/forum/showthread.php?85929-vl-every http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-8BF61C9E-1382-4168-A778-FEA394A361CC (setq lst1 (list 1 1 1) lst2 (list 1 2 3)) (vl-every '= lst1 (cdr lst1)) (vl-every '= lst2 (cdr lst2)) gr. Rlx Edited November 24, 2015 by rlx Quote Link to comment Share on other sites More sharing options...
Happy Hobbit Posted November 24, 2015 Author Share Posted November 24, 2015 Thanks for that Rix, I'm not too hot on VL functions & never heard of vl-every There were one or two errors in my code above, since amended Quote Link to comment Share on other sites More sharing options...
rlx Posted November 24, 2015 Share Posted November 24, 2015 Thanks for that Rix, I'm not too hot on VL functions & never heard of vl-every There were one or two errors in my code above, since amended till a couple of years ago neither did I but it really pays of to invest (vl-)some time in these functions gr. Rlx Quote Link to comment Share on other sites More sharing options...
Tharwat Posted November 24, 2015 Share Posted November 24, 2015 Try: (apply '= '(2 2 3)) Quote Link to comment Share on other sites More sharing options...
rlx Posted November 24, 2015 Share Posted November 24, 2015 Try: (apply '= '(2 2 3)) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted November 24, 2015 Share Posted November 24, 2015 .......... Quote Link to comment Share on other sites More sharing options...
Happy Hobbit Posted November 25, 2015 Author Share Posted November 25, 2015 Excellent Tharwat, thank you. One simple line of code replaces about 9 lines in my code. It does make me wonder how many AutoLISP functions are an amalgam of other functions though Quote Link to comment Share on other sites More sharing options...
Tharwat Posted November 25, 2015 Share Posted November 25, 2015 You're most welcome. Quote Link to comment Share on other sites More sharing options...
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.