But we can do somethings in C++ and Java to create lazy evaluation by constructing objects that store parameters for later evaluation.
class BigInteger;
class IntermediateSum {
const BigInteger &a, &b;
};
class BigInteger {
IntermediateSum operator+(const BigInteger &b) {
return new Intermediate(*this, b);
}
BigInteger& operator=(const IntermediateSum &i) {
/* now add */
}
};
The sum isn't evaluated until it hits the assignment. This lazy evaluation shows precisely when you can start evaluation and when you really need it.
No comments:
Post a Comment