Your intuition is correct, but Prolog uses the depth of the first design search (see the SLDNF resolution here ) and with good reasons, this limitation is not easily avoided.
OTOH, Ciao Prolog offers an appropriate extension.
You can simulate the width of the first recursion using a meta-interpreter, as is done, for example, here for left recursive DCG (left recursive grammars are a common case), but this is not an easy way to follow.
IMO - the most common extension that can approximate / satisfy your request is a tab, you can find it in YAP Prolog, XSB, B-Prolog.
source share