0

When user inputs 'i like prolog', or 'saya like Prolog' via Win-Prolog, the expected output will be 'saya suka prolog' or 'i suka Prolog' respectively, based on the code below:

words(saya,i).
words('Saya','I').
words(suka,like).
words('Suka','Like').
words(prolog,prolog).
words('Prolog','Prolog').

translation(X,Y):-
    words(X,Y).
translation(X,Y):-
    words(Y,X).
translation(X,X).

translate([], []).
translate([H|T], [H1|T1]):-
             translation(H, H1),
             translate(T,T1).

prolist([],[]).
prolist(SL,[W|T]):-
    split(SL,WL,R),
    name(W,WL),
    prolist(R,T).

split([],[],[]).
split([32|T],[],T).
split([H|T],[H|T2],R):-
    split(T,T2,R).  

run:-
    nl,write('Enter One sentence or word (English or Malay):'),
    read(X),end(X),
    nl.

end(X):-    
    X=q->write('SESSION END. THANK YOU. ');
    name(X,SL),prolist(SL,List),translate(List,W),
    nl,
    write('Translated as:'),
    write(W),
    nl,
    run.

but the outputs are as follows:

[i,like,prolog]
[saya,like,Prolog]

How to fix that? I'm not using SWI-Prolog, I knew how to do that SWI version of this code because the code is written for Win-Prolog.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Leon219
  • 1
  • 2
  • Win Prolog has removed their free trial downloads, so I cannot test. Could you make a rule to write a list like `my_write([]) :- nl.` and `my_write([H|T]) :- write(H), write(' '), my_write(T).` ? – TessellatingHeckler Jan 23 '22 at 03:07
  • I have a copy of the Win-Prolog downloaded file, here's the link: https://pastebin.com/8fdBHCnN – Leon219 Jan 23 '22 at 05:46

0 Answers0