Jump to content

Recommended Posts

Posted (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 by Happy Hobbit
Posted

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

Posted
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

Posted

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...