Costinbos77 Posted February 23, 2013 Posted February 23, 2013 (edited) Hello, can also be write and otherwise following expression: (foreach el (list 'Length 'Circumference 'ArcLength) (if (vlax-property-available-p vobi el) (setq per (vlax-get-property vobi el) )) ) to stop evaluation of a list on the first true respons ? Edited February 23, 2013 by Costinbos77 Quote
Lee Mac Posted February 23, 2013 Posted February 23, 2013 I don't quite understand the question, but maybe: (vl-some '(lambda ( x ) (if (vlax-property-available-p vobi x) (vlax-get-property vobi x))) '(length circumference arclength) ) Quote
MSasu Posted February 23, 2013 Posted February 23, 2013 Lee, I believe that this is exactly what Costinbos77 was looking for - a kind of End Foreach statement (similar with End For from VB, for example) that will abort the evaluation cycle at first encountered item that meets a certain condition. I'm proposing this to demonstrate the difference: (progn (foreach x '(1 2 5 3 5 4 5) (if (eq x 5) (print T) (print nil))) (princ)) vs. (progn (vl-some '(lambda(x) (if (eq x 5) (print T) (print nil))) '(1 2 5 3 5 4 5)) (princ)) Quote
Costinbos77 Posted February 23, 2013 Author Posted February 23, 2013 Thanks for the replies. I reformulated requirement. vl-Some function will stop evaluating to the first true response ? Since the foreach function evaluates the entire list of items. Quote
Lee Mac Posted February 23, 2013 Posted February 23, 2013 vl-Some function will stop evaluating to the first true response ? Since the foreach function evaluates the entire list of items. Correct - see the demonstrations provided by MSasu above. Quote
Costinbos77 Posted February 23, 2013 Author Posted February 23, 2013 I tried the expression: (progn (vl-some '(lambda(x) (princ "\n ") (princ (if (= x 5) (setq a x) "NO")) (princ " ;")) '(1 2 5 3 5 4 5)) (princ)) The result was: NO ; ' Only one! Supposed to be two.' ... and a = nil It seems that the evaluation stops on the first false. I need reverse, first true. Quote
MSasu Posted February 23, 2013 Posted February 23, 2013 I believe that this is what you were looking to obtain: (vl-some '(lambda(x) (princ "\n") (princ (if (= x 5) (progn (setq a x) "Done")))) '(1 2 5 3 5 4 5)) Quote
Lee Mac Posted February 23, 2013 Posted February 23, 2013 Consider this example: _$ (vl-some '(lambda ( x ) (print x) (= x 5)) '(0 1 2 5 3 4 5)) 0 1 2 5 T Quote
Costinbos77 Posted February 23, 2013 Author Posted February 23, 2013 It seems that : (vl-some '(lambda(x) (princ "\n ") (princ (if (= x 5) (setq a x) [color=red]vvv[/color])) (princ " ;")) '(1 2 5 3 5 4 5)) if vvv /= nil , stop the evaluetion of lambda funtion . Quote
MSasu Posted February 23, 2013 Posted February 23, 2013 Your code will stop evaluation at first item since the LAMBDA function will return always T due to the last last evaluation (PRINC)! Did you tested the correction proposed on post #7? Quote
Costinbos77 Posted February 23, 2013 Author Posted February 23, 2013 (setq [color=red]per[/color] (if (setq per (vl-some '(lambda ( x ) (if (vlax-property-available-p vobi x) (vlax-get-property vobi x))) '(length circumference arclength) ) ) ; setq per 0) ;_ end of if ) ; setq per variable must be a number Thank you guys! Quote
Lee Mac Posted February 23, 2013 Posted February 23, 2013 (if (null (setq per (vl-some '(lambda ( x ) (if (vlax-property-available-p vobi x) (vlax-get-property vobi x))) '(length circumference arclength) ) ) ) (setq per 0.0) ) 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.