Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-03-02 (17:09)
From: Christophe Raffalli <Christophe.Raffalli@u...>
Subject: Re: callcc/throw...

If you really need callcc/throw (that is try ... with ... is not  enough), this
means you are implementing an algorithm which is bactracking. callcc needs to
save the current stack. this is not very hard as you can copy only the first
page of the stack and delay the other copy when needed. However this keeps a
lot of pointer and will often leads to a lot of memory leaks.

Indeed the stack may contains value that are not related to your backtracking
or that could be recomputed easely. 

It is often better (not always) to directly implement your algorithm with the
bactracking explicit (that is keeping a stack of state from which you can

The code is often more difficult to write (you are doing a CPS translation by
hand) but you can gain a lot by
  - keeping only what is needed in the state
  - not keeping the state from which you know you do not need to backtrack
(most of the time you have a lot of these which are preserved in the stack if
you use callcc)

Christophe Raffalli