Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Quietly Exiting a Lisp Routine using (exit) or (quit)

1,959 views
Skip to first unread message

Paul Turvill

unread,
May 18, 1999, 3:00:00 AM5/18/99
to
The best way is to simply avoid using (exit) and (quit). I have written
several hundred AutoLISP routines, and have never found a situation where
(exit) or (quit) is needed in the final program. They can be handy during
debugging, however, especially if you're dealing with multiply-nested
loops.
__
<zep...@ns.net> wrote in message
news:374202e9...@news.sac.verio.net...
> Does anyone know how to exit a lisp routine quietly wihtout all the
> code barfing up on your text window?


Dave Zinn

unread,
May 18, 1999, 3:00:00 AM5/18/99
to zep...@ns.net
Put your code inside a cond statement. If the condition is not met, send
a simple statement and no burpage...

(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


zep...@ns.net

unread,
May 19, 1999, 3:00:00 AM5/19/99
to

KenLloydS

unread,
May 19, 1999, 3:00:00 AM5/19/99
to
Yes, I can help.

Put the line:

(princ)

before the closing parathesis of your routine and all will be well.


Bruce Chapman & Barbara Carey

unread,
May 19, 1999, 3:00:00 AM5/19/99
to

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

Paul Turvill

unread,
May 19, 1999, 3:00:00 AM5/19/99
to
No. (quit) and (exit) exit immediately, and bypass all other code,
including the (princ) function.
__
KenLloydS <kenl...@aol.com> wrote in message
news:19990518222513...@ng-fx1.aol.com...
0 new messages