0

I need to delete an item from a list of predicates, but it's not working. It returns true for me yet the item is still there.

Code:

eliminar :- limpar,
    write('\n*** DELETAR ***\n'),
    write('O que deseja deletar ?\n'),
    pegarString(X),
    doenca(X),
    format('~Doença: ~w ~n Sintoma: ~w ~n',[X]),
    retract(doenca([X,_]));
    write('  ').
pegarString(S) :-
    read_line_to_codes(user_input,C),
    name(S,C).
perguntadd(X) :- limpar,
    write('\n*** ADICIONAR ***\n'),
    write('\nDigite o nome da doença que deseja adicionar\n'),
    pegarString(X).
adicionar(X) :-
    format('Digite o sintoma da doença ~w?~n ',[X]),
    pegarString(I),
    assertz(doenca([X,I])),
    format('~n~w foi adicionado aos registros!~n~n',[X]).
repeat
  • 18,496
  • 4
  • 54
  • 166
martur94
  • 111
  • 10
  • 2
    Please provide a [mcve] that demonstrates your issue. From the code you have currently provided it's impossible to tell what's happening. – Steven Nov 25 '15 at 03:45
  • ok reissued can see all variable now. – martur94 Nov 25 '15 at 04:08
  • It looks likely to me that you have defined `doenca/1` statically. You should have a `:- dynamic doenca/1.` line somewhere in the top of the file, and it is very suspicious to me that you have both `doenca(X)` and `retract(doenca([X,I]))` in the same rule body, which just cannot succeed. Is there more source? – Daniel Lyons Nov 25 '15 at 06:47

1 Answers1

0

low level issues in first clause:

...
format('~Doença: ~w ~n Sintoma: ~w ~n',[X]),
retract(doenca([X,_]));
write('  ').

Specially the ';' looks suspicious. I guess you want instead

forall(retract(doenca([X,Sintoma])),
       format('~Doença: ~w ~n Sintoma: ~w ~n',[X,Sintoma])),
write('  ').

Also, I would consider better design to store doenca/2 instead of doenca/1.

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • 1
    I almost feel like semicolons `;` at the end of the line in Prolog code should be highlighted as errors by editors/IDEs. –  Nov 25 '15 at 08:35