Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Quit versus Clear["Global`*"]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121276] Re: Quit versus Clear["Global`*"]
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Wed, 7 Sep 2011 05:39:19 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Reply-to: jfultz at wolfram.com

In response to Andrzej...I agree this is idiomatic.  Quit has had this behavior 
since before I started using Mathematica (1993, in case you were wondering), and it probably dates back all the way to v1.  With such a long history, I don't see 
the eccentricity as being so out of the norm as to merit correction now.  I
don't know the history for sure, but I suspect you can chalk it up as a 
convenience feature for the console version of Mathematica (which, on many 
machines, was the only version available for many years).

In response to others...Quit really behaves just like any other function, 
requiring function application to zero or one arguments, except in one very
special case...when it constitutes the entirety of a standalone input.  The
argument-less version doesn't even quit when it's within a 
CompoundExpression...i.e.,

In[1]:= Quit; (* doesn't quit *)
In[2]:= Quit (* quits *)

So, if In[$Line] were assigned the symbol Quit, then the kernel will terminate.  
Otherwise, it evaluates Quit normally just as any other function.  This may
appear a bit confusing when using a front end because it *does* quit (as has
been noted in this thread) when used in a series of multiple statements in the 
front end as so:

2+2 (* first line of cell *)
Quit (* second line of same cell *)
4+4 (* third line of same cell *)

However, that doesn't at all violate the rule I set out above.  The front end 
treats newlines inside Input cells as terminating a complete In[] expression if 
the expression up to that point is syntactically correct and complete.  So, for 
example, when violating the following inputs all in one cell:

2 +
 2
3!
4*2

$Line increments three different times...once for "2+2", once for "3!", and once 
for "4*2".

Sincerely,

John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.


On Tue, 6 Sep 2011 03:57:45 -0400 (EDT), DrMajorBob wrote:
> Quit appears to quit as soon as it is parsed, regardless of arguments...
> yet another poster found that, if it is the first line in a cell with
> other statements, Mathematica doesn't quit until those other statements
> are done, hence wiping out their effect.
>
> Quit[e] the conundrum.
>
> Bobby
>
> On Mon, 05 Sep 2011 13:15:07 -0500, Andrzej Kozlowski <akoz at mimuw.edu.pl>
> wrote:
>
>> Well, I see it differently. All Mathematica functions have the form
>> Head[arguments] where the number of arguments could be 0. Quit is
>> therefore a Mathematica function, like Print[], Return[]. In fact,
>> Quit[n] where n is an integer also works "passing the integer n as an
>> exit code to the operating system" whatever that means. On the other
>> hand, expressions of the form Abracadabra are normally just symbols and
>> normally they do not perform any actions. In fact, do you know of any
>> other example (except Quit) when when evaluating a symbols actually does
>> more than return a value (that usually happens in the case of global
>> constants, whose names begin with $,
>>
>> [1]:= $Version
>>
>> Out[1]= 8.0 for Mac OS X x86 (64-bit) (February 23, 2011)
>>
>> Note, by the way, that Abort[] works but Abort does not:
>>
>> In[3]:= Print[a];Abort[];Print[b]
>> During evaluation of In[3]:= a
>> Out[3]= $Aborted
>>
>> Print[a];Abort;Print[b]
>> a
>> b
>>
>> Andrzej Kozlowski
>>
>>
>> On 5 Sep 2011, at 19:44, DrMajorBob wrote:
>>
>>> I, on the other hand, never saw Quit[] until this thread began.
>>>
>>> I suppose it figures that if Quit kills the kernel, then also Quit[any
>>> arguments or none] might also kill the kernel. (The other way 'round
>>> doesn't necessarily "figure", on the other hand.)
>>>
>>> Bobby
>>>
>>> On Mon, 05 Sep 2011 07:44:17 -0500, Andrzej Kozlowski
>>> <akoz at mimuw.edu.pl> wrote:
>>>
>>>> Actually (as far as I can tell) Quit is undocumented but Quit[] is:
>>>>
>>>> ?Quit
>>>> Quit[] terminates a Mathematica kernel session.
>>>>
>>>> I thought you had made a mistake but I tired just Quit (without the
>>>> brackets) and was surprised (after all these years!) to see it
>>>> work. I
>>>> am wondering if there are more cases like this?
>>>>
>>>> Andrzej Kozlowski
>>>>
>>>> On 5 Sep 2011, at 13:06, DrMajorBob wrote:
>>>>
>>>>> No. For that, you need:
>>>>>
>>>>> Quit
>>>>>
>>>>> Bobby
>>>>>
>>>>> On Sun, 04 Sep 2011 17:06:32 -0500, Themis Matsoukas
>>>>> <tmatsoukas at me.com>
>>>>> wrote:
>>>>>
>>>>>> So, if I use ClearAll["Global`*"] at the beginning of a
>>>>>> notebook and
>>>>>> execute all the cells, is it the same as running on a fresh
>>>>>> kernel?
>>>>>>
>>>>>> Themis
>>>>>
>>>>>
>>>>> --
>>>>> DrMajorBob at yahoo.com
>>>>
>>>
>>> --
>>> DrMajorBob at yahoo.com






  • Prev by Date: Re: Quit versus Clear["Global`*"]
  • Next by Date: Re: Quit versus Clear["Global`*"]
  • Previous by thread: Re: Quit versus Clear["Global`*"]
  • Next by thread: Re: Quit versus Clear["Global`*"]