FIXED! Re: [m-dev.] [Bug] write_term...

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Sat Mar 4 11:43:27 AEDT 2006


've fixed the bug in term_io.write_term: it now correctly writes out
disjoint terms without mucking up the nesting and program logic.  The
output demonstrated in the bug report is now fixed to the following:

----- BEGIN OUTPUT ----------------------------------------
n --> {(a(1), X = 1, (b, Y = 1, (c, Z = 1 ; Z = 2) ; Y = 2, Z = 2) ; X = 2, Y = 2, Z = 2), A = 1}, loopy, format("\n%% A(%d), X(%d), Y(%d), Z(%d)\n", [i(A), i(X), i(Y), i(Z)]).
:- pred loopy(io :: di, io :: uo) is det.
loopy --> nl, read_term(T), print_term(T).
:- pred print_term(read_term(T) :: in, io :: di, io :: uo) is det.
print_term(term(Varset, Term)) --> write_term(Varset, Term), print("."), loopy.
print_term(Err @ error(_2, _3)) --> print(Err), nl.
print_term(eof) --> [].
:- pred a(int :: in) is semidet.
a(1).
:- pred b is failure.
b :- fail.
:- pred c is failure.
c :- fail.

% A(1), X(1), Y(2), Z(2)
----- END OUTPUT ------------------------------------------

which, of course, compiles correctly (note the outermost parenthese are
now in place, but also note that inner parentheses are not duplicated
redundantly) and when given a source file on stdin, produces the equivalent 
source file on stdout.

The fix is as per the following diff -u for library/term_io.m
(ROTD-2006-03-01):

--- term_io.sav 2006-03-03 19:08:32.000000000 -0500
+++ term_io.m   2006-03-03 19:08:46.000000000 -0500
@@ -302,6 +302,18 @@
         term_io__write_term_args(Ops, BracedTail, !VarSet, !N, !IO),
         io__write_char('}', !IO)
     ;
+        % DMA, PR20060303: ';' terms conjoined with others lose their
+        % DMA              proper nesting ... add parentheses around
+        % DMA              the disjoint terms to preserve the order.
+        Functor = term.atom(";"),                  % DMA
+        Args = [Pre, Post]                         % DMA
+    ->                                             % DMA
+       io.write_char('(', !IO),                    % DMA
+       term_io.write_term(!.VarSet, Pre, !IO),     % DMA
+       io.write_string(" ; ", !IO),                % DMA
+       term_io.write_term(!.VarSet, Post, !IO),    % DMA
+       io.write_char(')', !IO)                     % DMA
+    ;                                              % DMA
         % The empty functor '' is used for higher-order syntax: Var(Arg, ...)
         % gets parsed as ''(Var, Arg). When writing it out, we want to use
         % the nice syntax.
----- END DIFF -U ----------------------------------------

Please, please, please put in this fix before release 0.13.  Thank you.

Sincerely,
Doug Auclair

--------------------------------------------------------------------------
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