Author Topic: Quit vs Exit in AutoLisp  (Read 12087 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 493
Quit vs Exit in AutoLisp
« on: December 30, 2014, 07:44:59 AM »
Whats the difference between Quit and Exit in AutoLisp ?


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Quit vs Exit in AutoLisp
« Reply #1 on: December 30, 2014, 07:53:28 AM »

Essentially none.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Quit vs Exit in AutoLisp
« Reply #2 on: December 30, 2014, 08:18:43 AM »
TIC - One is poor technique and the other is lazy programing.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Quit vs Exit in AutoLisp
« Reply #3 on: December 30, 2014, 08:37:19 AM »
TIC - One is poor technique and the other is lazy programing.

Please explain.


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Quit vs Exit in AutoLisp
« Reply #4 on: December 30, 2014, 10:07:20 AM »
These are relevant to your question:

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/quit-vs-exit/td-p/836439
http://www.afralisp.net/autolisp/tutorials/cond-vs-if.php

PS
The TIC is Tongue In Cheek and a dated expression meaning an attempt at humor.
Although a poor one I must admit. 
« Last Edit: December 30, 2014, 10:11:02 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Quit vs Exit in AutoLisp
« Reply #5 on: December 30, 2014, 10:44:04 AM »
I'd never seen that COND vs IF article on afralisp before; nice link CAB.

I agree with the use of COND over IF; I've had a few arguments over the use of IF vs COND and keeping the namespace hygienic. ...Not to mention the use of a BOOLE in place of a simple COND or IF statement (that drives me batty when the tactic is misused).

If I remember right, I would use QUIT in dialog box situations and not so much in regular application situations (you need to properly set up your error handler environment to handle their use). I assembled "a better error handler", from a few people's efforts. (just search the "show your stuff" forum for my name and error) that should get you started if you wanted to.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Quit vs Exit in AutoLisp
« Reply #6 on: December 30, 2014, 11:47:24 AM »
These are relevant to your question:

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/quit-vs-exit/td-p/836439
http://www.afralisp.net/autolisp/tutorials/cond-vs-if.php

PS
The TIC is Tongue In Cheek and a dated expression meaning an attempt at humor.
Although a poor one I must admit. 


As per the links shared by you, there is no difference between quit and exit.

However, if AUTOLISP has made these two commands, there has to be a difference.

There cannot be two commands for exactly same thing.

It would be good to know the difference for academic purposes. :-D


JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Quit vs Exit in AutoLisp
« Reply #7 on: December 30, 2014, 11:51:17 AM »
Why does there have to be a difference?

http://theswamp.org/~john/avlisp/#exit
http://theswamp.org/~john/avlisp/#quit

Set up an error handler and test them each.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Bhull1985

  • Guest
Re: Quit vs Exit in AutoLisp
« Reply #8 on: December 30, 2014, 12:13:08 PM »
These are relevant to your question:

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/quit-vs-exit/td-p/836439
http://www.afralisp.net/autolisp/tutorials/cond-vs-if.php

PS
The TIC is Tongue In Cheek and a dated expression meaning an attempt at humor.
Although a poor one I must admit. 


As per the links shared by you, there is no difference between quit and exit.

However, if AUTOLISP has made these two commands, there has to be a difference.

There cannot be two commands for exactly same thing.

It would be good to know the difference for academic purposes. :-D

Could it just be that Autodesk assumed when exiting (or quitting) an app that the majority of persons would be accustomed to using one of these two commands?
And rather than to have the "quit"ters receive an 'Unknown command "QUIT". Press F1 for help.'
or
the "exit"ers have the opposite...they just decided to implement both commands for fluidity?
That's what I would guess, especially reading that there are no documented differences at least shown in this thread.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Quit vs Exit in AutoLisp
« Reply #9 on: December 30, 2014, 12:41:30 PM »
TIC - One is poor technique and the other is lazy programing.

I completely agree - there are very few cases in which such functions cannot be avoided, in my mind they are the equivalent of resorting to a goto statement to control code evaluation...

Perhaps one of the few situations in which the use of such functions is unavoidable is within a vl-catch-all-apply expression to essentially break evaluation of a vlax-for expression when a certain condition is met in order to avoid unnecessary iteration of an entire collection - but this is also a rare case.

As for the difference between the two, as far as I am aware, there is none. This may seem redundant, but then remember that AutoLISP is a high-level language and consequently there are many functions which are present merely for convenience - after all, any cond expression can be written using a sequence of nested if expressions, any loop could be written using while, 1+/1- are entirely superfluous, etc. etc.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Quit vs Exit in AutoLisp
« Reply #10 on: December 30, 2014, 03:22:39 PM »
Quote from: mailmaverick
As per the links shared by you, there is no difference between quit and exit.

The links said it.
I said it.
John's excellent avlisp help file for theSwamp saya it
The AutoLisp Help files said it.


Quote from: mailmaverick

However, if AUTOLISP has made these two commands, there has to be a difference.

Why does there have to be a difference ?


Quote from: mailmaverick

There cannot be two commands for exactly same thing.

Why ?

Quote from: mailmaverick

It would be good to know the difference for academic purposes. :-D

Academic pursuits are excellent but you need to check your premises. There is no difference and no amount of assumptions and second guessing will change that.



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Quit vs Exit in AutoLisp
« Reply #11 on: December 30, 2014, 03:35:58 PM »
I haven't been around AutoLisp / lisp long enough but could it be a legacy issue.
New function name created & old name not removed.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Quit vs Exit in AutoLisp
« Reply #12 on: December 30, 2014, 03:36:50 PM »
They are spelled different.

From the Lisp Console
Code: [Select]
_$ exit
#<SUBR @0000000031fde8b8 QUIT>
_$ quit
#<SUBR @0000000031fde8b8 QUIT>
_$
So looks like they both evaluate to calling the same subroutine.

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Quit vs Exit in AutoLisp
« Reply #13 on: December 30, 2014, 07:46:35 PM »
TIC - One is poor technique and the other is lazy programing.

I completely agree - there are very few cases in which such functions cannot be avoided, in my mind they are the equivalent of resorting to a goto statement to control code evaluation...

...

I apologize I am typing this via my phone so I'm keeping this brief.
goto is all together different. Comparing apples to oranges.

I wouldn't say that the functions usage is all that bad either (the goto is a negative connotation); after all they did make vl-exit-with-message.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org


David Bethel

  • Swamp Rat
  • Posts: 656
Re: Quit vs Exit in AutoLisp
« Reply #15 on: January 01, 2015, 07:13:41 AM »
An interesting read form Compuserve days in 1997 :


I wonder if Owen holds the same thoughts today <g>

I still use (exit) and (quit) regularly.

  • Verifying release versions.
  • Verifying External reference or support file existance
  • Etc
-David
« Last Edit: January 01, 2015, 07:16:47 AM by David Bethel »
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Quit vs Exit in AutoLisp
« Reply #16 on: January 01, 2015, 09:13:06 AM »
TIC - One is poor technique and the other is lazy programing.
I completely agree - there are very few cases in which such functions cannot be avoided, in my mind they are the equivalent of resorting to a goto statement to control code evaluation...
...
goto is all together different. Comparing apples to oranges.

IMO, (exit) / (quit) is no different to saying "goto *error* function".

I wouldn't say that the functions usage is all that bad either (the goto is a negative connotation); after all they did make vl-exit-with-message.

The negative connotation was intentional - in my opinion, continued use of these functions breeds lazy programming as CAB has noted earlier: rather than crafting an appropriate conditional expression to control the program evaluation such that the program exits cleanly for all foreseeable scenarios, many may settle for simply crashing the program at any point if something doesn't go as planned...

Lee

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Quit vs Exit in AutoLisp
« Reply #17 on: January 01, 2015, 11:00:36 AM »
I wonder if Owen holds the same thoughts today <g>

Hah! I'll have to reread the thread to refresh my memory, but I'm pretty sure I held the same opinions about (quit) back then that I do today. It basically depends on your perspective. If your goal is purely functional, then you probably don't care either way. If your goal is to produce beautiful code, then some people will find one way more "beautiful" and some the other. I want to integrate and transcend both beauty and function, and make code that is *good*, even approaching perfection of form. And that requires the use of (quit), IMO. :)

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Quit vs Exit in AutoLisp
« Reply #18 on: January 01, 2015, 11:29:41 AM »
Yep. This is pretty much how I would do it today. Note that the error is percolated right up the stack of error handlers into the previous handler, rather than presuming to know best and preventing the user from having any control.
Code: [Select]
(defun MyFun (/ ErrExit MyError OldErr Handle)
  (defun ErrExit (msg) (MyError msg) (exit))
  (defun MyError (msg)
    (if Handle (CloseHandle Handle))
    (if OldErr
      (progn
        (setq *error* OldErr OldErr nil)
        (if (listp *error*) (*error* msg) (princ msg))))
  )
  (setq OldErr *error* *error* MyError)
  (if (WrongPlatform)
    (ErrExit "Wrong Platform, You Idiot!"))
  (if (WrongOS)
    (ErrExit "Wrong OS, You Ignorant Dufus!"))
  (setq Handle (OpenConnection))
  (if (WrongDatabase)
    (ErrExit "Sheesh!  You Are A Real Dingleberry!"))
  (DoStuff)
  (CloseConnection Handle)
)

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Quit vs Exit in AutoLisp
« Reply #19 on: January 01, 2015, 03:20:25 PM »
LOL

Idiot Dufus Dingleberry  That's me! 
R12 Dos - A2K

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Quit vs Exit in AutoLisp
« Reply #20 on: January 05, 2015, 01:55:32 PM »
TIC - One is poor technique and the other is lazy programing.
I completely agree - there are very few cases in which such functions cannot be avoided, in my mind they are the equivalent of resorting to a goto statement to control code evaluation...
...
goto is all together different. Comparing apples to oranges.

IMO, (exit) / (quit) is no different to saying "goto *error* function".

I wouldn't say that the functions usage is all that bad either (the goto is a negative connotation); after all they did make vl-exit-with-message.

The negative connotation was intentional - in my opinion, continued use of these functions breeds lazy programming as CAB has noted earlier: rather than crafting an appropriate conditional expression to control the program evaluation such that the program exits cleanly for all foreseeable scenarios, many may settle for simply crashing the program at any point if something doesn't go as planned...

Lee
Sorry for the late reply; I just got back from holiday vacation.

That describes every function call. -e.g. "goto sqrt <number>".

The negative connotation goto received was because of it's use in the C language; it's overuse created what is called spaghetti code. Lisp(ers) has a bad habit of this as well (one of the main reasons I created LiFP). But I digress, using Quit/Exit will give more robust code. However--and admittedly--its use is often overlooked and missed. They are not "bad" functions at all, just underused.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Quit vs Exit in AutoLisp
« Reply #21 on: January 05, 2015, 01:57:02 PM »
Nice error handler owenwengerd. :)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Quit vs Exit in AutoLisp
« Reply #22 on: January 05, 2015, 06:40:16 PM »
< .. > But I digress, using Quit/Exit will give more robust code. However--and admittedly--its use is often overlooked and missed. They are not "bad" functions at all, just underused.

 :yes:
I agree, providing there is a well designed mechanism to trap the error/exit and restore the environment to a pristine condition.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

RAYAKMAL

  • Guest
Re: Quit vs Exit in AutoLisp
« Reply #23 on: January 05, 2015, 07:02:56 PM »

(defun c:QY  () (command "quit" "y"))  :-D

And I use EXIT when using DCL

Code: [Select]

   (if (not (new_dialog "ddblkmgr_info_dlg" dh))
       (exit)
   )
   (set_tile "ddblkmgr_info_dlg_lbl" "DDBlock Manager v.1 1995")
   ... ... ..
« Last Edit: January 05, 2015, 07:10:39 PM by RAYAKMAL »

danallen

  • Guest
Re: Quit vs Exit in AutoLisp
« Reply #24 on: January 05, 2015, 08:10:04 PM »
and I bet you turn autosave off...

(defun c:QY  () (command "quit" "y"))  :-D

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Quit vs Exit in AutoLisp
« Reply #25 on: January 06, 2015, 08:41:53 AM »
That describes every function call. -e.g. "goto sqrt <number>".

Not quite -

When a function (such as sqrt) is evaluated, program evaluation resumes at the expression following the call to the function (without error); conversely, when (exit) or (quit) are used, program evaluation is ceased by forcing an error, hence my comparison to a 'goto *error* function'...

But I digress, using Quit/Exit will give more robust code.

How? Could you elaborate?
« Last Edit: January 06, 2015, 08:52:34 AM by Lee Mac »

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Quit vs Exit in AutoLisp
« Reply #26 on: January 06, 2015, 10:00:31 AM »
Quote
But I digress, using Quit/Exit will give more robust code.

I agree.  To me, (exit / quit) is more like 'Go directly to jail, DO NOT pass Go, DO NOT collect $200'.   Less chances for screw ups
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Quit vs Exit in AutoLisp
« Reply #27 on: January 06, 2015, 10:09:26 AM »
Quote
But I digress, using Quit/Exit will give more robust code.

I agree.  To me, (exit / quit) is more like 'Go directly to jail, DO NOT pass Go, DO NOT collect $200'.   Less chances for screw ups

But how is forcing an error any more robust than writing a condition to cleanly complete evaluation of the defun expression?

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Quit vs Exit in AutoLisp
« Reply #28 on: January 06, 2015, 10:35:19 AM »
Quote
But I digress, using Quit/Exit will give more robust code.

I agree.  To me, (exit / quit) is more like 'Go directly to jail, DO NOT pass Go, DO NOT collect $200'.   Less chances for screw ups

But how is forcing an error any more robust than writing a condition to cleanly complete evaluation of the defun expression?

I don't understand either Lee. 

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Quit vs Exit in AutoLisp
« Reply #29 on: January 06, 2015, 02:14:09 PM »
While it is probably possible to test for evey possible scenario prior to
calling a set_mode or any other function, it is far more straight forward ( IMO )
to issue an (exit) / (quit) and have the error handler cancel out any active command
, end the undo group and then undo all changes to database, and then issue the
return_mode function in a single step.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;++++++++++++ Set Modes & Error ++++++++++++++++++++++++++++++++++
  3. (defun nw_smd ()
  4.  (SetUndo)
  5.  (setq olderr *error*
  6.       *error* (lambda (msg)
  7.                 (while (> (getvar "CMDACTIVE") 0)
  8.                        (command))
  9.                 (and (/= msg "quit / exit abort")
  10.                      (princ (strcat "\nError: *** " msg " *** ")))
  11.                 (and (= (logand (getvar "UNDOCTL") 8) 8)
  12.                      (command "_.UNDO" "_END" "_.U"))
  13.                 (nw_rmd)))
  14.  
  15.  (setvar "INSBASE" '(1 1 0))
  16.  
  17.  (princ))
  18.  
  19. ;++++++++++++ Return Modes & Error +++++++++++++++++++++++++++++++
  20. (defun nw_rmd ()
  21.   (setq *error* olderr)
  22.   (command "_.UNDO" "_END")
  23.   (prin1))
  24.  
  25. ;++++++++++++ Set And Start An Undo Group ++++++++++++++++++++++++
  26. (defun SetUndo ()
  27.  (and (zerop (getvar "UNDOCTL"))
  28.       (command "_.UNDO" "_ALL"))
  29.  (and (= (logand (getvar "UNDOCTL") 2) 2)
  30.       (command "_.UNDO" "_CONTROL" "_ALL"))
  31.  (and (= (logand (getvar "UNDOCTL") 8) 8)
  32.       (command "_.UNDO" "_END"))
  33.  (command "_.UNDO" "_GROUP"))
  34.  
  35. ;++++++++++++ Test Bed +++++++++++++++++++++++++++++++++++++++++++
  36. (defun c:exitquit (/ olderr a)
  37.  
  38. (nw_smd)
  39.  
  40. (and (wcmatch (getvar "ACADVER") "*13*")
  41.      (wcmatch (getvar "PLATFORM") "*Win*")
  42.      (setq a "13WIN"))
  43.  
  44. (entmake (list (cons 0 "CIRCLE")(cons 40 1)(list 10 0 0 0)))
  45.  
  46. (if (/= a "13WIN")
  47.     (progn
  48.       (alert "This Program Only Work In Release 13 For Windows")
  49.       (exit)))
  50.  
  51. (nw_rmd)
  52.  
  53.  


Without using the *error* handler, INSBASE remains '(1 1 0)
Also any geometry created prior to the abort remains.

This is a scenario I have due the fact my rendering program only runs in Release 13 Windows. 

But only if I choose a AccuRender2 as an option.  If it is a hidden line, shaded surface, wireframe image,
the autocad release doesn't matter.

If the value is an option based on user inputs nested deeply in the main program, thats a lot
code to have to clear out.

I'm sure there are arx programs that have similar limitations and simply exit when
trying to be loaded on incorrect platforms.
R12 Dos - A2K

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Quit vs Exit in AutoLisp
« Reply #30 on: January 06, 2015, 04:04:45 PM »
I literally have one minute so I will type fast.

https://en.wikipedia.org/wiki/Tail_call#History

I really don't want to engage in a "Worse is Better" type of discussion so I will part with the last bit of wisdom I have regarding the topic. As a programmer you should not be codified (thinking there are always structured rules and regulations) when receiving/processing/outputting information outside the "walls" of your application. ...but you know that (it is up to you to decide).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org