0

I am working on a program for a college assignment, currently I'm trying to write some denials from an abductive procedure written on a file as integrity constraints, but I'm having some problems.

My predicates for the task look like this:

append_denials(_, []).
append_denials(File, [fail(_, Den)|Tail]) :-
    open(File, append, Stream), 
    write(Stream, 'ic :- '),
    write_denials(Stream, Den),    
    write(Stream, '.'),
    nl(Stream),
    close(Stream),
    append_denials(File, Tail).

write_denials(Stream, [T]) :-
    write(Stream, T).                      
write_denials(Stream, [H|T]) :-
    write(Stream, H), 
    write(Stream, ', '),
    write_denials(Stream, T).

And they are queried with something along these lines:

append_denials('denyagain.txt', [fail([_C],[battery_flat(_C),lights_go_on(_C)]),fail([_D],[has_no_fuel(_D),\+fuel_indicator_empty(_D),\+broken_indicator(_D)])]).

The problem is that they seem to work if I put them on a separate file (with these predicates and nothing else), but when used within the program (3000 lines of Prolog that I can't post here...) I get this error:

! Domain error in argument 1 of write/2
! expected stream, but found '$stream'(139681177337584)
! goal:  write('$stream'(139681177337584),\+broken_indicator(_116))
% source_info

I checked and I can confirm that the predicates are not being overwritten... I really don't understand how this could be happening.

Any suggestion or clues regarding where I might be going wrong would be very welcome!

Many thanks, David.

  • '$stream'(139681177337584) actually seems really like a stream, maybe a closed one... I think you're experiencing unexpected backtracking (i.e. what about write_denials failure?). Anyway, there is no point in closing/reopening the file. – CapelliC Jul 29 '13 at 18:19
  • Thank you very much, your comment made me start tinkering with cuts, adding one to the base case of write_denials did the job. Now I'm going to look into avoiding opening/reopening the file. Many thanks! – Daniel Bora Jul 30 '13 at 08:51

0 Answers0