$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Jim Apple (japple_at_[hidden])
Date: 2003-12-13 23:42:14
New syntax possible:
int choose(int n, int k) {
function<int (int,int)> choose = memoize(choose);
if ((k == 0) || (k == n)) {
return 1;
} else {
return choose(n-1,k-1) + choose(n-1,k);
}
}
"memoize" doesn't have to go through its whole creation and binding
procedure for each recursive call, though, because it is actaully
memoized. It need only look up the answer from previous calls.
I could also build in a third parameter with type memo_p_t, with default
value "memoized." If choose is called as
choose(x,y,no_memo)
the function<int (int,int)> choose is initialized with the int
choose(int,int).
Jim