Jump to content

Completion and evaluation of a list of items


Recommended Posts

Posted (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 by Costinbos77
Posted

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

Posted

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

Posted

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.

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

Posted

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.

Posted

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

Posted

Consider this example:

_$ (vl-some '(lambda ( x ) (print x) (= x 5)) '(0 1 2 5 3 4 5))
0 
1 
2 
5 T

Posted

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 .

Posted

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?

Posted

(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!

Posted
(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)
)

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