MathGroup Archive 2008

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

Search the Archive

Re: Stopping a program

  • To: mathgroup at smc.vnet.net
  • Subject: [mg93277] Re: Stopping a program
  • From: carlos at colorado.edu
  • Date: Sun, 2 Nov 2008 01:56:41 -0500 (EST)
  • References: <200810300700.CAA00553@smc.vnet.net> <geee6l$a8n$1@smc.vnet.net>

On Oct 31, 2:04 am, Daniel Lichtblau <d... at wolfram.com> wrote:
> car... at colorado.edu wrote:
> > This is a revision of a previous posting "Looking for Stop".
> > Unfortunately the answers were not helpful.  My fault: I didnt
> > explain what I am looking for in specific terms.  So here it is.
>
> > Several application programs in Mathematica that I use in
> > graduate courses are translations from old (1960-80s) Fortran and C
> > programs.  A medium-size Fortran program with, say, 10^6 statements
> > contracts to about 40-100K Mathematica commands, and similarly in
> > other high order languages. The reduction comes mostly from
> > use of built-in functions. However, the overall hierarchical
> > structure
> > does not change much, e.g. the "main program" becomes a
> > "Driver Script Cell"  (DSC) and functions/routines become Modules.
> > The typical structure is
>
> > DSC:
> >        Preprocessing Modules (written by students)
> >        Processing Modules (supplied)
> >        Postprocessing Modules (supplied)
>
> > There are typically 50-200 supplied modules, forming trees 3-6
> > levels deep, depending on application.   Programs are run
> > interactively by students doing homework or take-home exams.
> > They write the problem-dependent preprocessing part of the DSC,
> > save the NB, initialize the supplied modules (which are in
> > untouchable initialization cells) and execute the DSC.
>
> > Now suppose an irrecoverable error is detected in a Module four levels
> > deep. In Fortran or C,  I give diagnostics and call a central error
> > termination routine that also displays the "call trace" kept in a
> > stack.
> > In Mathematica I can only say Exit[], which is a bit drastic.
>
> > What I was looking for is a way to transfer to the end of the DSC
> > as if the program had terminated normally.  The student looks at
> > the error message, fixes the preprocessing part as needed, and
> > tries again.  As mentioned in the OP, I thought to put a Label:
> > at the end of the DSC but AFAIK Mathematica does not allow
> > forward control transfers.  Specific suggestions are welcome.
>
> Mathematica certainly supports allowing Label to syntactically follow
> corresponding Goto(s) (I have used it this way). But I doubt this is
> what you want because they really need to be in the same Module, With,
> or Block. (Maybe they don't, but I'd not bet on them working correctly
> if not).
>
> You almost certainly can achieve what you have in mind with Throw at the
> point of error, and Catch in the DSC. That's generally how we transfer
> control back to caller in error situations. Other possibilities include
> using Check in your DSC, and Return at points of error. But this
> involves really knowing where Return will take you and thus is not
> reliable if you are neted several layers deep.
>
> Daniel Lichtblau
> Wolfram Research

My experience with Catch and Throw in C++ (esp. write-only code
written by PhD students) has been discouraging. I think the old
fashioned way described by Don Knuth in his "Structured Programming
with goto Statements" is still the best to cut through multiple layers.
But it requires a compilable language.

How about a simple addition to Mathematica 7: Stop [ options ].
One of the options, perhaps default, could be "Stop execution
of the topmost executing cell and return control to front end".
For 4.1 through 6.0 I can keep Exit[].


  • Prev by Date: Re: Re: 3D Graphics in a Palette or Dialog
  • Next by Date: Re: Sum[n^(-n), {n, 1, Infinity}]
  • Previous by thread: Re: Stopping a program
  • Next by thread: Re: Stopping a program