[Nickle] continuation bug in nickle
Plutonium 186
nickle@nickle.org
Fri, 18 Apr 2003 22:03:38 +0000
The following code was intended as an example in the Nickle tutorial about
continuations. It implements a simple binary tree search that longjmp()s out
when the match is found; however, although longjmp() seems to be jumping
somewhere (as evidenced by the debug statements), it does not jump to the
setjmp() (as evidenced by the other debug statements). This seems like a
bug.
-----
typedef tree;
typedef struct {
int key;
poly data;
&poly left, right;
} tree;
void function search ( tree t, int i, &continuation c ) {
if ( i < t.key && ! is_void ( t.left ) )
search ( t.left, i, &c );
else if ( i > t.key && ! is_void ( t.right ) )
search ( t.right, i, &c );
else if ( i == t.key ) {
printf ( "key found\n" );
longjmp ( c, t.data );
assert(false, "longjmp failed\n" );
}
}
tree t = { key = 2, data = "blah", left = reference ( <> ), right =
reference ( <> ) };
continuation c;
int i = 0;
poly p = setjmp ( &c, <> );
++i;
printf ( "I have been here %d times.\n", i );
if ( is_void ( p ) )
search ( t, 2, &c );
else
printf ( "value = %g\n", p );
-----
Robert Burgess
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail