(cond ((= x 1)
(princ "\njust an example")
(princ "\nplease continue")
)
(t
(princ "\nCondition not met, cannot continue!")
)
)
zep...@ns.net wrote:
> Does anyone know how to exit a lisp routine quietly wihtout all the
> code barfing up on your text window?
>
> Example:
>
> (If (=x 1)
> (progn
> (alert "just an example")
> (alert "please continue")
> );end_progn
> ;else do the following
> (exit)
> );end_if
>
> Now the rest of my lisp routine is printed onto the text window if x
> results in something other than 1. I would prefer that it would just
> exit and return the user to the command line without showing all the
> extra code. Same thing goes for (quit).
>
> Any help would be greatly appreciated.
> Thanks,
> Jeff
> je...@hlagroup.com
Put the line:
(princ)
before the closing parathesis of your routine and all will be well.
The Other solutions have some merit but don't answer the question
directly. (QUIT) and (EXIT) both call (*ERROR*) if its defined, so all
you have to do is define your own *error* function before calling exit.
like this
...
(defun *error*(msg)
(princ)
)
(exit)
However I find that sometimes your own *error* function stays defined
even though the scope of it is local to the function where the error (in
this case EXIT) occurs, so it pays to undefine *error* in the *error*
function thus
...
(defun *error*(msg)
(setq *error* nil)
(princ)
)
(exit)
When I tried this in R14, it just put "*Cancel*" on the screen. no code
back trace!
To reiterate what others have said, you shouldn't need to call exit or
quit in production software, but it is handy for debugging. If another
solution is not feasible, then it MAY indicate your program is not very
well structured. When coding don't think in terms of "if its wrong stop"
but think "if its OK do the next step", all the wrong stuff drops out
the bottom.
Another useful function that stops part way through something is AND, it
stops as soon as an argument evaluates to nil, so you can put blocks of
code in their own progn which returns nil if (and only if) that block
needs to prevent execution of all remaining blocks. Then wrap all the
progn's in an AND function.
eg
(and
(progn
<some steps>
(if <its OK> T nil) ;;; it this if returns nil the and will not
;;; execute the next progns
)
(progn
<some more steps>
(if <its OK> T nil) ;;; it this if returns nil the and will not
;;; execute the next progn
(progn
<some more steps>
(if <its OK> T nil) ;;; it this if returns nil the and will not
;;; execute the next progns
)
) ;;; the AND returns T if all progn's returned T else it
;;; returns nil (ie a failure somewhere)
Hope this helps
--
Bruce Chapman
CADenzA Software
New Zealand
email: cad...@xtra.co.nz