racket/collects/honu/examples/even-odd.honu
Stevie Strickland 439c1ecd24 Several bugs found, the biggest being using <:_P to compare members
of a supertype and subtype, where the subtype was not yet added to
the tenv.  Had to hack to get around that one.

Also little problems like the fact that list can be captured by the
user program, so we can't use that -- used list* (with a null at the
end) and null (for empty lists) instead.

Since the power was down and I couldn't get the earlier stuff committed,
I have even more changes.  Bug-fixes, mostly, though now top-level
functions that are defined consecutively are mutually recursive as they
should be.

svn: r300
2005-07-03 00:28:59 +00:00

24 lines
471 B
Plaintext

// This tests mutually recursive function definitions.
bool even(int n) {
cond {
n == 0 => return true;
n < 0 => return even(-n);
else return odd(n - 1);
};
}
// If the following line is uncommented, loading this file
// should fail because even and odd are no longer considered
// mutually recursive.
//
// _ = null;
bool odd(int n) {
cond {
n == 0 => return false;
n < 0 => return odd(-n);
else return even(n - 1);
};
}