The trick to recursion is that we would like it to terminate eventually ( at least we usually do ) . One way to guarantee termination of recursion is to se primitive recursion. This amounts to taking a thing to recurse on , and making sure that the next call is closer to a terminal condition than the call that got us here. In practice , we can assure this either by decrementing an integer or each call ( and terminating at zero , or some other goal ) , or by taking only the tail of a list for each successive call ( and terminating at an empty list ). Both versions of factorial listed in the example assume they will be passed an integer greater than zero ( and will fail otherwise; exercise: how?)
derementing