Make addSubstitution recursive

This means that if the keys of the new keys -> value (coming from
unifying the values) has a key in common with the rest (because of
recursive definitions), then addSubstitution is retried, instead of
immediately adding a new entry.

A new entry is added if there is nothing in common.  In case of
recursive definitions, a few recursions pulls in all of the variables
that will end up being unified, so at some point common becomes empty.

This commit correctly puts the SLD solution to cosld test in infinite
loop, because no matter what answer it tries it is never grounded.

Signed-off-by: Shahbaz Youssefi <ShabbyX@gmail.com>