From: Han Yi
Subject: [Q] restart a function from exit point
Date: 
Message-ID: <hanyi.768618714@bruce.cs.monash.edu.au>
Hello, does anyone out there know how to restart a function from the point it
exit last time? In other words, you throw 'something to catch 'somthing, then
after doing a bit calculation, is there anyway you can go back to the throw
point and continue to throw 'something-else?
      Here is the background: I have a function called 'find-a-plan' and a
function called 'evaluate-plan. A parent function of these two functions calls
'find-a-plan to get a plan. When a plan is returned, it calls 'evaluate-plan
to evaluate the plan. If the plan is not good enough, it calls 'find-a-plan
to get the next plan. Since the 'find-a-plan function is doing recursive 
searching, I want it can be restarted from the point which it exited last  
time so that it can continue the recursive searching.

     Any suggestion is welcome. Many thanks in advance.

Yi Han
Department of Computer Science
Monash University
Clayton, Australia.
E-mail: ·····@bruce.cs.monash.edu.au

From: Jeff Dalton
Subject: Re: [Q] restart a function from exit point
Date: 
Message-ID: <CpnGLI.BAv@cogsci.ed.ac.uk>
In article <···············@bruce.cs.monash.edu.au> ·····@cs.monash.edu.au (Han Yi) writes:
>Hello, does anyone out there know how to restart a function from the point it
>exit last time? In other words, you throw 'something to catch 'somthing, then
>after doing a bit calculation, is there anyway you can go back to the throw
>point and continue to throw 'something-else?
>      Here is the background: I have a function called 'find-a-plan' and a
>function called 'evaluate-plan. A parent function of these two functions calls
>'find-a-plan to get a plan. When a plan is returned, it calls 'evaluate-plan
>to evaluate the plan. If the plan is not good enough, it calls 'find-a-plan
>to get the next plan. Since the 'find-a-plan function is doing recursive 
>searching, I want it can be restarted from the point which it exited last  
>time so that it can continue the recursive searching.

There isn't any simple and portable way to do it.  Here are some
possibilities, going progressively further from what you asked for:

  * Use a Lisp that has co-routines or something similar such as
    stack groups or lightweight processes.

  * Rewrite find-a-plan to use an "agenda".  When it has a choice,
    it picks one possibility and adds an agenda entry that will allow
    it to try the rest of the possibilities.  When find-a-plan returns,
    each agenda entry represents a "choice point" from which it can
    continue the search.  (This is sort of like doing recursion with
    an explicit stack except that you don't have to try the most 
    recently added agenda entry first.)  Agenda entries are often 
    functions because that's a simple way to save states of different
    shapes.

  * Rewrite find-a-plan so that it returns a list of all valid
    plans (a "list of successes") but use "lazy lists" instead of
    ordinary lists.  By a "lazy list" I mean what the Scheme
    literature calls a "stream".  See e.g. the Abelson and Sussman
    book _The Structure and Interpretation of Computer Programs_.

  * Have find-a-plan call evaluate-a-plan or else call an
    evaluation function passed in as a parameter.

-- jeff
From: Jeffrey Mark Siskind
Subject: Re: [Q] restart a function from exit point
Date: 
Message-ID: <QOBI.94May11164714@qobi.ai.toronto.edu>
In article <··········@cogsci.ed.ac.uk> ····@aiai.ed.ac.uk (Jeff Dalton) writes:

   In article <···············@bruce.cs.monash.edu.au> ·····@cs.monash.edu.au
   (Han Yi) writes:
   >Hello, does anyone out there know how to restart a function from the point
   it
   >exit last time? In other words, you throw 'something to catch 'somthing,
   then
   >after doing a bit calculation, is there anyway you can go back to the throw
   >point and continue to throw 'something-else?
   >      Here is the background: I have a function called 'find-a-plan' and a
   >function called 'evaluate-plan. A parent function of these two functions
   calls
   >'find-a-plan to get a plan. When a plan is returned, it calls
   'evaluate-plan
   >to evaluate the plan. If the plan is not good enough, it calls 'find-a-plan
   >to get the next plan. Since the 'find-a-plan function is doing recursive 
   >searching, I want it can be restarted from the point which it exited last  
   >time so that it can continue the recursive searching.

   There isn't any simple and portable way to do it.  Here are some
   possibilities, going progressively further from what you asked for:

     * Use a Lisp that has co-routines or something similar such as
       stack groups or lightweight processes.

     * Rewrite find-a-plan to use an "agenda". [...]

     * Rewrite find-a-plan so that it returns a list of all valid
       plans (a "list of successes") but use "lazy lists" instead of
       ordinary lists. [...]

     * Have find-a-plan call evaluate-a-plan or else call an
       evaluation function passed in as a parameter.

There is a *MUCH* better and easier way to do all of this. Use Screamer.
Screamer adds nondeterministic programming constructs to CommonLisp. You just
make FIND-A-PLAN nondeterministic with the EITHER construct and then if
EVALUATE-PLAN doesn't like the plan it can reject it with the FAIL construct.
This will backtrack and allow FIND-A-PLAN to return a second time with a
different solution. Screamer thus does exactly what you want. See my home page
on the Web for copies of papers on Screamer and for details on how to get an
automatic destribution for free. If you wish I can send you a pedagogical
implementation of the McAllester and Rosenblit systematic nonlinear planner in
under 100 lines of code.

    Jeff (home page ftp://ftp.cs.toronto.edu/pub/qobi/qobi.html)
--

    Jeff (home page ftp://ftp.cs.toronto.edu/pub/qobi/qobi.html)
From: Jeff Dalton
Subject: Re: [Q] restart a function from exit point
Date: 
Message-ID: <Cpovvn.8xx@cogsci.ed.ac.uk>
In article <··················@qobi.ai.toronto.edu> ····@CS.Toronto.EDU writes:
>In article <··········@cogsci.ed.ac.uk> ····@aiai.ed.ac.uk (Jeff Dalton) writes:
>
>   In article <···············@bruce.cs.monash.edu.au> ·····@cs.monash.edu.au
>   (Han Yi) writes:
>   >Hello, does anyone out there know how to restart a function from the point
>   it
>   >exit last time? In other words, you throw 'something to catch 'somthing,
>   then
>   >after doing a bit calculation, is there anyway you can go back to the throw
>   >point and continue to throw 'something-else?

>   There isn't any simple and portable way to do it.  Here are some
>   possibilities, going progressively further from what you asked for:
>
>     * Use a Lisp that has co-routines or something similar such as
>       stack groups or lightweight processes.
>
>     * Rewrite find-a-plan to use an "agenda". [...]
>
>     * Rewrite find-a-plan so that it returns a list of all valid
>       plans (a "list of successes") but use "lazy lists" instead of
>       ordinary lists. [...]
>
>     * Have find-a-plan call evaluate-a-plan or else call an
>       evaluation function passed in as a parameter.
>
>There is a *MUCH* better and easier way to do all of this. Use Screamer.

I regard that as a variant of my first suggestion: use a Lisp that
has co-routines or something similar.

How poerable is Screamer.  I did try it in KCL once, which is a 
fairly good sign so far as CLtL One is concerned.

>Screamer adds nondeterministic programming constructs to CommonLisp. You just
>make FIND-A-PLAN nondeterministic with the EITHER construct and then if
>EVALUATE-PLAN doesn't like the plan it can reject it with the FAIL construct.
>This will backtrack and allow FIND-A-PLAN to return a second time with a
>different solution. Screamer thus does exactly what you want. See my home page
>on the Web for copies of papers on Screamer and for details on how to get an
>automatic destribution for free. If you wish I can send you a pedagogical
>implementation of the McAllester and Rosenblit systematic nonlinear planner in
>under 100 lines of code.

Please send me one.  I would find it extremely interesting.

-- jeff
From: Lou Steinberg
Subject: Re: [Q] restart a function from exit point
Date: 
Message-ID: <LOU.94May11174200@atanasoff.rutgers.edu>
In article <···············@bruce.cs.monash.edu.au> ·····@cs.monash.edu.au (Han Yi) writes:

   Hello, does anyone out there know how to restart a function from
   the point it exit last time? In other words, you throw 'something
   to catch 'somthing, then after doing a bit calculation, is there
   anyway you can go back to the throw point and continue to throw
   'something-else?
	 Here is the background: I have a function called
   'find-a-plan' and a function called 'evaluate-plan. A parent
   function of these two functions calls 'find-a-plan to get a plan.
   When a plan is returned, it calls 'evaluate-plan to evaluate the
   plan. If the plan is not good enough, it calls 'find-a-plan to get
   the next plan. Since the 'find-a-plan function is doing recursive
   searching, I want it can be restarted from the point which it
   exited last time so that it can continue the recursive searching.

What you want is "continuation-passing", which can be done in common
lisp (See Charniak, et al, AI Programming) but is easier in scheme
(see "call-with-current-continuation" [or something like that?]  in
the scheme manual).
--
					Lou Steinberg

uucp:   {pretty much any major site}!rutgers!aramis.rutgers.edu!lou 
internet:   ···@cs.rutgers.edu