From: Kwan Chin
Subject: How do I jump out of recursive?
Date: 
Message-ID: <chinkw.810014533@marsh>
Hi,

  Just got one small problem..  

    I've got a recursive function which will got a certain depth to 
search for answers, if the solution is found, it is printed and the user
is prompted whether they wanted to continue.....

e.g
    (setf ContinueFlag 'YES)

    (defun Solve (...,....)
     (if (eql 'YES ContinueFlag)
       (
                :
                :
                :    ))

Is there a way of achieving this without using global flag?  I am using
Sussex POPLOG version 14.1.

Thanks very much for your time.

From: Jack Harper
Subject: Re: How do I jump out of recursive?
Date: 
Message-ID: <jharper-0209950800120001@p1.denver1.dialup.csn.net>
In article <················@marsh>, ······@cs.curtin.edu.au (Kwan Chin) wrote:

> Hi,
> 
>   Just got one small problem..  
> 
>     I've got a recursive function which will got a certain depth to 
> search for answers, if the solution is found, it is printed and the user
> is prompted whether they wanted to continue.....
> 
> e.g
>     (setf ContinueFlag 'YES)
> 
>     (defun Solve (...,....)
>      (if (eql 'YES ContinueFlag)
>        (
>                 :
>                 :
>                 :    ))
> 
> Is there a way of achieving this without using global flag?  I am using
> Sussex POPLOG version 14.1.
> 
> Thanks very much for your time.

Sir:

I am not familiar with Sussex POPLOG, and therefore am probably wrong --
But, if POPLOG has CATCH/THROW, I would very much suggest those.


Regards.


Jack Harper
Bank Systems 2000, Inc
Golden, Colorado USA
From: Barry Margolin
Subject: Re: How do I jump out of recursive?
Date: 
Message-ID: <42idot$ctn@tools.near.net>
In article <················@marsh> ······@cs.curtin.edu.au (Kwan Chin) writes:
>    I've got a recursive function which will got a certain depth to 
>search for answers, if the solution is found, it is printed and the user
>is prompted whether they wanted to continue.....

This is a good place to use CATCH and THROW:

(defun solve (...)
  (catch 'solve-done
    (solve-internal ...)))

Now rename the recursive function to SOLVE-INTERNAL, and at the place where
you want to get out you put:

(throw 'solve-done <result>)
-- 
Barry Margolin
BBN PlaNET Corporation, Cambridge, MA
······@bbnplanet.com
Phone (617) 873-3126 - Fax (617) 873-5124
From: Bernhard Pfahringer
Subject: Re: How do I jump out of recursive?
Date: 
Message-ID: <42mhjm$11g8@ftp.univie.ac.at>
In article <··········@tools.near.net>,
Barry Margolin <······@nic.near.net> wrote:
>
>This is a good place to use CATCH and THROW:
>
Alternatively you could use "return-from" with a locally defined
recursive function (using "lables"):

(defun solve (<args>)
   (labels ((solve-internal (...) 
               ...
               (return-from solve some-result)
               ... ))
       (solve-internal <args>)))

As usual with Common Lisp, you can achieve the same result in quite
different ways :-)

Bernhard
-------------------------------------------------------------------------
Bernhard Pfahringer
Austrian Research Institute for  
Artificial Intelligence          ········@ai.univie.ac.at 
Schottengasse 3                  Fax:   (+43 1) 532-0652
A-1010 Vienna, Austria           Phone: (+43 1) 533-6112