如何与prolog中的给定事实相匹配的谓词转换数字与单词
我想进行此示例:gradeinwords(Stud04,“数据库”,翻译)。 = [五,九]尝试了此代码以打印学生成绩 用文字的特定课程,我无法在事实和代码之间链接,因为我是prolog的新手,我无法弄清楚如何做到这一点或添加到代码,以便它运行良好 事实是学生(Stud04,“数据库”,59)。
代码 :
totext(0, zero).
totext(1, one).
totext(2, two).
totext(3, three).
totext(4, four).
totext(5, five).
totext(6, six).
totext(7, seven).
totext(8, eight).
totext(9, nine).
gradeInWords(Student, Course, translate) :-
translate([], []).
translate([Head|Tail], [TranslatedHead|TranslatedTail]) :-
totext(Head, TranslatedHead),
translate(Tail, TranslatedTail).
I want to make this example : gradeInWords(stud04,'Database',translate). = [five,nine] tried this code to print a student grade
at specific course in words, i cant link between the fact and the code as i am new to prolog and i cant figure out how to do that or what to add to code so it work well
the fact is student(stud04,'Database',59).
code :
totext(0, zero).
totext(1, one).
totext(2, two).
totext(3, three).
totext(4, four).
totext(5, five).
totext(6, six).
totext(7, seven).
totext(8, eight).
totext(9, nine).
gradeInWords(Student, Course, translate) :-
translate([], []).
translate([Head|Tail], [TranslatedHead|TranslatedTail]) :-
totext(Head, TranslatedHead),
translate(Tail, TranslatedTail).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论