caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jonathan Harrop <jdh30@jdh30.plus.com>
To: caml-list@yquem.inria.fr, Michael Wohlwend <micha-1@fantasymail.de>
Subject: Re: [Caml-list] recursive or loop
Date: Mon, 06 Mar 2006 13:33:08 +0000	[thread overview]
Message-ID: <200603061322.k26DMU1E016749@nez-perce.inria.fr> (raw)

On Mon Mar  6 12:09 , Michael Wohlwend <micha-1@fantasymail.de> sent:
>Is that true?

No.

>How do I jump out of a recursive algorithm and be able to 
>continue it at the same point?

If you're doing purely functional programming then you'll be passing the state as an argument to the 
recursive function. So you just raise an exception that carries the current state, catch it outside 
and save the state. To restart you just load the state and pass it as an argument to the recursive 
function.

If you're doing impure programming (i.e. with side-effects) then you do the same sort of thing but 
instead of carrying the state in the exception you have to capture it yourself (as you do in the 
looping version) and reset it yourself before you restart.

There is probably no difference in difficulty.

Cheers,
Jon.


             reply	other threads:[~2006-03-06 13:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-06 13:33 Jonathan Harrop [this message]
2006-03-06 14:15 ` Thomas Fischbacher
2006-03-06 16:42   ` Michael Wohlwend
2006-03-06 17:25 Jonathan Harrop
2006-03-06 18:25 ` Michael Wohlwend
2006-03-06 18:31   ` Thomas Fischbacher
2006-03-08 19:07     ` Matthew O'Connor
2006-03-08 21:56       ` Thomas Fischbacher
2006-03-08 22:10         ` Till Varoquaux
2006-03-08 22:13           ` Thomas Fischbacher
2006-03-08 23:28             ` Jon Harrop
2006-03-06 19:25   ` Anil Madhavapeddy
2006-03-06 21:22     ` Michael Wohlwend
2006-03-07 16:02       ` Alan Falloon
2006-03-08  7:53         ` Michael Wohlwend

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200603061322.k26DMU1E016749@nez-perce.inria.fr \
    --to=jdh30@jdh30.plus.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=micha-1@fantasymail.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).