Prolog without if and else statements

后端 未结 4 757
南方客
南方客 2021-01-18 02:39

I am currently trying to learn some basic prolog. As I learn I want to stay away from if else statements to really understand the language. I am having trouble doing this th

4条回答
  •  粉色の甜心
    2021-01-18 03:21

    If you really want to try to understand the language, I recommend using CapelliC's first suggestion:

    sample(A, B, _,  1) :- A > B.
    sample(A, B, C,  C) :- A == B.
    sample(A, B, _, -1) :- A < B.
    

    I disagree with CappeliC that you should use the if/then/else syntax, because that way (in my experience) it's easy to fall into the trap of translating the different constructs, ending up doing procedural programming in Prolog, without fully grokking the language itself.

提交回复
热议问题