Jump to content

if (item of member of list) is equal 0.0 (remove member)


Recommended Posts

Posted

HI everyone

I have this list: ((0.0 70.8187) (0.0 -119.977) (61.875 44.4858)) or ((88.21 0.0) (19.80 0.0) (61.875 44.4858))

I want remove all member if x=0 or y=0 then remove members of list==> ((61.875 44.4858))

Posted

With that I want to remove, you pretty much don't need computer or state of mind...

Posted

dear marko:

It is possible to say what you mean more clearly.

Unfortunately, I did not understand what you mean.

Posted
(defun foo (lst)
    (vl-remove-if '(lambda (x) (or (zerop (car x)) (zerop (cadr x)))) lst)
)

 

  • Like 1
  • Thanks 1
Posted

Hi Jonathan Handojo:

thx for reply

I used your advice and my problem was solved.
thanks again.

Posted

Given that we're working with reals, I would suggest the use of the equal function with an appropriate tolerance - I would reserve zerop for when testing integer values.

 

Hence:

(vl-remove-if '(lambda ( x ) (or (equal (car x) 0.0 1e-8) (equal (cadr x) 0.0 1e-8))) lst)

 

Or, for any coordinate:

(vl-remove-if '(lambda ( x ) (vl-some '(lambda ( y ) (equal y 0.0 1e-8)) x)) lst)

 

  • Like 2
  • Thanks 1
Posted
3 hours ago, reza said:

Dear Jonathan:

🙏🙏🙏
thanks a lot again.

No worries. Glad to help.

However, I do agree with what Lee mentioned. His function should be slightly more bulletproof than mine.

Posted

HI Everyone:

Thx Lee Mac for reply and attention 🙏🙏

Thx Jonathan 🙏🙏

  • 1 month later...
Posted (edited)
On 10/21/2022 at 11:37 PM, marko_ribar said:

With that I want to remove, you pretty much don't need computer or state of mind...

Deleted

Edited by troggarf
Posted

Dear troggarf:
I'm sorry that I paid attention to your reply so late.
I have used the advice of experts like you and dear Marko many times in different forums.
I think it's my fault that I bore Marco with very simple questions.

🙏🙏🙏

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...