[m-dev.] [Bug] write_term: improper representation of nesting of compound disjoint goals
    doug.auclair at logicaltypes.com 
    doug.auclair at logicaltypes.com
       
    Sat Mar  4 08:01:23 AEDT 2006
    
    
  
Dear all,
There appears to be a bug in term_io.write_term/4.  When I write out a
compound disjoin set of goals, it gets the parentheses wrong, particularly
for the outermost disjoint term (the parentheses disappear).  So, a
compilable Mercury program, when read then written back out using
term_io.write_term/4 is no longer compilable.  The example of a compilable
program becoming uncompilable follows:
----- BEGIN CODE -----------------------------------------
:- module problem_write_term.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.
:- implementation.
:- import_module string, list, term_io.
main -->
  { (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 at error(_, _)) --> 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.
----- END CODE -------------------------------------------
The output of
$ ./problem_write_term < problem_write_term
is:
----- BEGIN OUTPUT ----------------------------------------
:- module problem_write_term.
:- interface.
:- import_module io.
:- pred main(io :: di, io :: uo) is cc_multi.
:- implementation.
:- import_module string, list, term_io.
main --> {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 obviously doesn't compile (note the missing outermost paratheses that
are supposted to precede a(1) and precede A = 1):
Making Mercury/cs/problem_write_term.c
[...]
problem_write_term.m:008: In clause for `main(di, uo)':
problem_write_term.m:008:   mode mismatch in disjunction.
problem_write_term.m:008:   `A' :: free, unique(1).
For more information, try recompiling with `-E'.
** Error making `Mercury/cs/problem_write_term.c'.
I think this could be a pretty easy fix, but I also think it's a pretty
important one: could this fix go in before release 0.13, please?
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