Michaels Posted October 28, 2011 Posted October 28, 2011 (edited) Hello . How can I check if a point of coordinates is a member in a list of points ? (setq pts '((27.3814 14.1609 0.0) (24.6235 10.9329 0.0) (19.8956 13.6626 0.0) (17.6971 9.85463 0.0))) (setq pt '(27.3814 14.1609 0.0)) (member pt pts) Thanks in advance Edited October 28, 2011 by Michaels Forgot to type comman for the list of points Quote
LISP2LEARN Posted October 29, 2011 Posted October 29, 2011 (defun C:test (/ pts pt) (setq pts '((27.3814 14.1609 0.0) (24.6235 10.9329 0.0) (19.8956 13.6626 0.0) (17.6971 9.85463 0.0))) (setq pt '(27.3814 14.1609 0.0)) (if (member pt pts) (princ "\n Point list found") (princ "\n Point list not found") ) (princ) ) Quote
Michaels Posted October 29, 2011 Author Posted October 29, 2011 Thank you so much . My try was the same as yours , and I do wonder why it did not work for me at the beginning !!! Cheers Quote
David Bethel Posted October 29, 2011 Posted October 29, 2011 Watch out for (member) calls in lists that contain REALs. There isn't a fuzz factor so the numbers must be exact matches. A lot depends on how the numbers were attained. -David Quote
alanjt Posted October 29, 2011 Posted October 29, 2011 Good point David. I guess you could roll your own... (defun _member (item lst) (if (car lst) (if (equal (car lst) item) lst (_member item (cdr lst)) ) ) ) Quote
Lee Mac Posted October 29, 2011 Posted October 29, 2011 (edited) Very elegant Alan A few variations: (defun _memberwithfuzz ( expr lst fuzz ) (vl-member-if '(lambda ( x ) (equal x expr fuzz)) lst) ) (defun _memberwithfuzz ( expr lst fuzz / x ) (while (and (setq x (car lst)) (not (equal expr x fuzz))) (setq lst (cdr lst)) ) lst ) (defun _memberwithfuzz ( expr lst fuzz / foo bar ) (defun foo ( x ) (equal x expr fuzz)) (defun bar ( x ) (if (foo x) (progn (defun foo ( x ) (list x)) (list x))) ) (apply 'append (mapcar 'bar lst)) ) Edited October 29, 2011 by Lee Mac Quote
David Bethel Posted October 29, 2011 Posted October 29, 2011 ;;;SearchAtom List Fuzz (defun memberfz (s l f / r) (foreach a l (and (not r) (equal s a f) (setq r T))) r) -David Quote
alanjt Posted October 29, 2011 Posted October 29, 2011 Very elegant Alan A few variations: Thanks, you too. Slight mod with definable fuzz factor... (defun _memberFuzz (item lst fuzz) (if (car lst) (if (equal (car lst) item fuzz) lst (_member item (cdr lst) fuzz) ) ) ) Quote
Michaels Posted October 30, 2011 Author Posted October 30, 2011 Thanks so much guys , I have lots of things to read . Highly appreciated . 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.