List Length in Prolog

You need to use an accumulator. While you could do something like this: which will recurse all the way down to the end of the list and then, as each invocation returns, add one to the length, until it gets back to the top level with the correct result. The problem with this approach is that … Read more