I find it a rare occasion that I need EXIT?
(defun _Document_Has_XRefs ( document / result )
(vl-catch-all-apply
(function
(lambda ( )
(vlax-for block (vla-get-blocks document)
(if (eq :vlax-true (vla-get-isxref block))
(progn
(setq result T)
(exit)
)
)
)
)
)
)
result
)
but maybe it was on CompuServe.Now you are showing your age. 8-)
As it stands, exit means (to me at least) that something's gone wrong and I need to cancel everything (exactly as if the user pressed ESC).
(if (= (strcase BsHgt) "LOW")
(progn
(if (< *LOWBUS* 98)
(progn
(aLERT "Too Low!")
(exit)
)
)
)
)
Somewhat contrived use of (exit):I think this would always return nil. Seeing as the first block in the blocks collection would be the model space - which isn't an xref. And thus the exit is called on the first block. Though you do mention it's a contrived usage ;)Code: [Select](defun _Document_Has_XRefs ( document / result )
(vl-catch-all-apply
(function
(lambda ( )
(vlax-for block (vla-get-blocks document)
(if (eq :vlax-true (vla-get-isxref block))
(progn
(setq result T)
(exit)
)
)
)
)
)
)
result
)
Cheers.
*allowing time for post edit before posting correction*Sorry ... yes I missed the progn when reading this. :-[ Stupid of me. Sorry MP! It's novel I must say!
I think this would always return nil. Seeing as the first block in the blocks collection would be the model space - which isn't an xref. And thus the exit is called on the first block.
do you have a non-vlisp example? I haven't learned all the Vlisp commandsHere's simplistic idea to show something which happens quite often:
the above could be combined using the LISP version of AND, once I learn how
Here is how I might code it:Code - Auto/Visual Lisp: [Select]
< .. >
I want the error condition to cause an immediate failure without getting propagated and without being hidden intside a fancy structure (or indented 20 spaces), and I want it to be obvious when scanning the code 30 years later what the control flow is here.
I shan't argue with your evident programming expertise Owen and I respect your opinion, but I can't say that this structure:Code - Auto/Visual Lisp: [Select]
) ) ) ) ) )
is any more readable than:Code - Auto/Visual Lisp: [Select]
(cond ( (failed-p (test1)) ) ( (failed-p (test2)) ) ( (failed-p (test3)) ) )
I don't think the level of indentation plays any part since both would have to be indented to the level at which the conditions are to be tested in any case.
I don't think the level of indentation plays any part since both would have to be indented to the level at which the conditions are to be tested in any case.