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.