caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] recursive or loop
@ 2006-03-06 13:33 Jonathan Harrop
  2006-03-06 14:15 ` Thomas Fischbacher
  0 siblings, 1 reply; 15+ messages in thread
From: Jonathan Harrop @ 2006-03-06 13:33 UTC (permalink / raw)
  To: caml-list, Michael Wohlwend

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.


^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [Caml-list] recursive or loop
@ 2006-03-06 17:25 Jonathan Harrop
  2006-03-06 18:25 ` Michael Wohlwend
  0 siblings, 1 reply; 15+ messages in thread
From: Jonathan Harrop @ 2006-03-06 17:25 UTC (permalink / raw)
  To: caml-list, Michael Wohlwend

On Mon Mar  6 16:42 , Michael Wohlwend <micha-1@fantasymail.de> sent:
>On Monday 06 March 2006 15:15, you wrote:
>> > If you're doing purely functional programming then you'll be passing the
>> > state as an argument to the recursive function.
>>
>> How do you restore the call stack?
>
>yes the state is not the problem, the callstack is the (my) problem...

Write in CPS?

Cheers,
Jon.


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-03-08 23:27 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-06 13:33 [Caml-list] recursive or loop Jonathan Harrop
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

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).