Skip to main content
GameDev.net gamedev.net
🔒 Locked

odd prolog problem

Started by nb2 Apr 14, 2009 at 5:05 PM 2 replies 900+ views
Original Post
nb2
nb2
Hi all, I don't know if this is the best place to post this question but here goes: I'm working on a prolog program that basically translates a list of chinese number into a list of english numbers or vice versa (depending on the arguments provided), here is my code:

translation(ling,zero).
translation(yi,one).
translation(er,two).
translation(san,three).
translation(si,four).
translation(wu,five).
translation(liu,six).
translation(qi,seven).
translation(ba,eight).
translation(jiu,nine).
translation(shi,ten).

translateE2C([],[]).
translateE2C([Ch|Ct],[Eh|Et]) :- translation(Ch, Eh), translateE2C(Ct,Et).
calling might look like: translateE2C([ling,yi,er],X). (output: X=[zero, one, two]) The program works exactly like it is supposed to up until a point. The only problem is that the output doesnt display the last part of the list when 9 or more words are provided to it (output: X = [zero, one, two, three, four, five, six, seven, eight|...]). I am just wondering why it is doing that at that point, and if there is any way to "force" it to print everything it is supposed to? Thanks for your help :)
iMalc
iMalc
The code looks right so it's probably something specific to the prolog interpreter you are using. It may be abbreviating the list intentionally. You'll need to state what interpreter you're using.

See if there is some option in the documentation to turn list abbreviation off.
Icon
Icon
The SWI-Prolog interpreter does this on purpose to avoid being too verbose I guess. See this other thread for changing that behaviour.

Alternatively you could roll your own output function, something like:
show([]).show([H|T]) :- write(H), write(', '), show(T).translate(X) :- translateE2C(X,Y), show(Y).
nb2
nb2
thanks!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.