Stopping recursion when list length = 1

I think it is unfair to blame Bratko. In the past several Prolog systems provided member/2 and append/3 as built-in and thus if you wanted to learn novices how append/3 works, you might not be able to (re)define append/3. In current SWI-Prolog it is a normal library predicate. I vaguely recall that some ISO revision defines it as a built-in again. I never bothered following that as append/3 is autoloaded and thus available. It does still allow you to define it as something else though, which is nice for educational reasons as well as running old small programs that included their own implementation. Surely, normal programs should use as much as possible from the library.

I’m not sure we should learn novices very early how append/3 can be implemented. If you to though, it is not always a good advice to look in the library. Some predicates have quite awkward implementations for performance, safety against cyclic terms, determinism and other (sometimes historical) reasons. If you are just starting to learn Prolog this can be a bit too much :slight_smile:

1 Like