[m-dev.] diff: fix bug in pprint__to_doc
Ralph Becket
rbeck at microsoft.com
Tue May 9 23:17:29 AEST 2000
> library/pprint.m:
> Fix a bug: there was an infinite loop in the code for `to_doc'.
> The recursive call to convert the term's arguments was
> happening even in the case where the term had no arguments.
This I don't understand. The only place where a recursive call
ocurrs in the original source is in the clausal part of the
function:
:-
deconstruct(X, Name, Arity, UnivArgs),
Args = list__map(
( func(UnivArg) = to_doc(Depth - 1, univ_value(UnivArg)) ),
UnivArgs
).
Now, I would (did) assume that after the call to deconstruct/4 that
(Arity = 0) <=> (UnivArgs = []), in which case the call to list__map/2
shouldn't have made any calls to to_doc/2 - if this is indeed the
error case.
Got it! The error case is actually when Arity > 0, but Depth =< 0.
This will lead to unwanted recursive calls.
Still, unless you've somehow created a circular structure, I don't
see how this would turn into an infinite loop (surely all terms are
finite trees?) Maybe your `infinite loop' was really just `very deep
recursion'?
Hmm. But the new version does indeed knock this bug on the head!
--
Ralph Becket | MSR Cambridge | rbeck at microsoft.com
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list