4 ms·
Can you expand on "base case for all functions"? I'm having a hard time figuring out a base case for say calling toString on an object, or incrementing an inte
by patrickthebold 9y ago
Can you expand on "base case for all functions"?
I'm having a hard time figuring out a base case for say calling toString on an object, or incrementing an integer.
- ballenf 9y agoNo because that comment was poorly worded and overbroad. I'll narrow it to say that drawing a parallel between base cases and preconditions might be helpful when dealing with functions / methods that are more complex than lambdas or their equivalents. Thanks, I should have thought through that part more carefully before posting.
- falcor84 9y ago> I'm having a hard time figuring out a base case for say calling toString on an object, or incrementing an integer. In both cases, we can special-case the "zero" of the domain. For example, toString of an object without any attributes would return '{}', while incrementing the integer zero would return 1. I'm not sure about the usability of the latter in an iterative approach, but the former could definitely be used as the basis of an iterative algorithm that traverses all of an object's attributes.